Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rails course day 4


Published on

This class was all about RESTful nature of rails applications.
We also practiced on nested controllers and views conventions.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Rails course day 4

  1. 1. Ruby on rails course By @AlSayedGamal
  2. 2. Views and Controllers Day 4
  3. 3. Agenda Routing Controllers and nested controllers Views and template engines
  4. 4. routing (routes.rb) General rules root 'pages#main' get '/patients/:id', to: ‘patients#show’ match 'photos', to: 'photos#show', via: [:get, :post] resources and nested resources url_for member and collection
  5. 5. Resutful Routes Note: the url helper methods
  6. 6. routing(routes.rb) get ‘:controller/:action/:id/with_user/:user_id' Naming routes (as:) via: [get, post or all] constraints: { subdomain: 'admin' }
 can save your life get 'books/*section/:title', to: ‘books#show' mount AdminApp, at: ‘/admin’ get 'こんにちは', to: 'welcome#index'
  7. 7. Controller Actions before_action layout respond_to head and status codes render views redirect_to with flash
  8. 8. Controller (Params) Hash, Array and JSON Parameters GET /clients?ids[]=1&ids[]=2&ids[]=3 def default_url_options
 { locale: I18n.locale }
 end Strong paramaters
  9. 9. Controller session, flash and cookies request object Send_data and send_file
  10. 10. Controllers
 (Request Specials) session, flash and cookies request object Send_data and send_file
  11. 11. add it to Gemfile and bundle rails g devise users rake db:migrate Notice the before_action filter Tip1: check “rails g”after installation. Tip2: check user model after generation.
  12. 12. Thanks