Upload
al-sayed-gamal
View
208
Download
2
Embed Size (px)
Citation preview
Ruby on rails course
By @AlSayedGamal
Views and Controllers
Day 4
Agenda
Routing
Controllers and nested controllers
Views and template engines
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
Resutful RoutesNote: the url helper methods
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'
Controller
Actions
before_action
layout
respond_to
head and status codes
render views
redirect_to with flash
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
Controller
session, flash and cookies
request object
Send_data and send_file
Controllers (Request Specials)
session, flash and cookies
request object
Send_data and send_file
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.
Thanks