Posts

Ruby on Rails MVC

Image
  Ruby on Rails MVC Like most of the other frameworks, Rails is also based on MVC pattern. It basically works as following: Requests first come to the controller, controller finds an appropriate view and interacts with model which in turn interacts with database and send response to controller. Then controller gives the output to the view based on the response. Model The models are classes in Rails. They interact with database, store data, handles validation, transaction, etc. This subsystem is implemented in  ActiveRecord  library. This library provides an interface between database tables and Ruby program code that manipulates database records. Ruby method names are automatically generated from database tables field names. View View represent data in a particular format in an application for the users. It handles HTML, CSS, JavaScript and XML in an application. They do what controller tells them. This subsystem is implemented in  ActionView  library. This libr...

Questions List

 Questions List 1- What is ruby and Ruby on rails. 2-  MVC pattern in rails.  

Download database from aws

 default: &default   adapter: mysql2   encoding: utf8   pool: 5   username: scadmin   password: 4w3som3C4t!   host: stg-09-29.cqilo8w4uzxl.us-west-1.rds.amazonaws.com   port: 3306   # socket: /var/run/mysqld/mysqld.sock development:   <<: *default   database: syncrew_development test:   <<: *default   database: syncrew_test production:   <<: *default   database: syncrew_production   pool: 35 mysqldump -u scadmin -p -h stg-09-29.cqilo8w4uzxl.us-west-1.rds.amazonaws.com syncrew_production > latesttt_sql_20102021.sql mysqldump -u database_name -p -h host database_name > latesttt_sql_20102021.sql Download it from browser http://3.101.121.6/latesttt_sql_20102021.sql

RVM and Gemset

 GemSet-  A  gemset  is just a container you can use to keep gems separate from each other. Creating a  gemset  per project allows you to change gems (and gem versions) for one project without breaking all your other projects. Each project need only worry about its own gems. RVM- RVM is a command-line tool for managing multiple ruby versions and also uses a separate gemset for each rails app. RVM is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems. [ source:  https://rvm.io/  (official rvm website) ] Ruby Version Manager, often abbreviated as RVM, is a software platform for Unix-like operating systems designed to manage multiple installations of Ruby on the same device. The entire ruby environment including the Ruby interpreter installed RubyGems, and documentation is partitioned. [ source: Wikipedia ] Why we need RVM Let’s see an example. S u ppose, you have ...

before_save & before_create

  before_save   is called every time an object is saved. So for new and existing objects. (create and update action) before_create  only before creation. So only for new objects (create action)

Suppose we have a Student with id=”4”. If we delete the Student with id=”4”, what will be the result of the following queries:

  Student.find(4) Student.find_by_id(4) Student.find(4)  will raise an error:  ActiveRecord::RecordNotFound: Couldn't find Student with id=4 Student.find_by_id(4)  will return  nil  and will not raise an error.

Mention the differences between the observers and callbacks in ruby on rails.

  Following are the differences between observers and callbacks in ruby on rails: – Rails observers:  these are same as callbacks but are used when the method is not directly associated to the life cycle of the object. It lives for a longer duration of time and can be attached or detached at any time. Rails callback:  the callback methods can only be called at only certain points of time in the life cycle of an object like validation, creation, updating, deletion, etc. Unlike the rails observers, the rails callback lives for only a short period of time.