Rails 5 All topic Notes
- 2. 1) Browser sends request to
server for the html page
2) Router routes the request
To the controller of the
Demanded page.
3) A) Controller checks if page
Is available in the view. if yes then send page back to
the server
4) Controller sends
requested page to server
3) B) else controller takes
data from database using
model and send to the
view. page is created in the
view based on the data.
- 3. 1) Generate new Rails project (type inside console)
Rails new project_name -d database
example: Rails new myapp –d MYSQL
Extra info…. 1) then-> cd myapp 2) then-> bundle install 3) bundle exec command to check
why command is not working]
2) Generate new controller (type inside console)
Rails g controller controller_name methodnames..(optional)
example: Rails g controller wecome index
3) Generate new model (type inside console)
Rails g model model_name columnatme:datatype…
example: Rails g model name:string password:string
- 4. 4) Generate migration ( type inside controller)
A) Rails g migration migrationname (simple migration)
Example: rails g migration createtable
B) Rails g migration AddXXXToYYY ( Add column in the table)
Example: rails g migration AddDateToEmployee
C) Rails g migration RemoveXXXFromYYY (Remove column from the table)
Example: rails g migration RemoveDateFromEmployee
5) Go to config/database.yml file. Then set database name ,
username , password and mysql socket name
rake Db:schema:dump
rake db:migrate (will create or modify table according to migration)
6) Go to config/route.rb file. And place universal matching pattern
match ‘controller(/:action(/:id))’ , :via => :get
7) To start rails server : Rails server
To stop rails server : ctrl+c