3. $ rake routes
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
ROR Lab.
15. Controller
Namespacing
scope "/admin" do
resources :posts, :comments
without Admin:: module prefix
ROR Lab.
16. Nested Resources
class Magazine < ActiveRecord::Base
has_many :ads
end
class Ad < ActiveRecord::Base
belongs_to :magazine
resources :magazines do
resources :ads
ROR Lab.
17. Nested Resources
resources :magazines do
resources :ads
ROR Lab.
19. More RESTful
Actions
• Member Routes
resources :photos do
member do
get 'preview'
end
URL : /photos/1/preview with GET
Named Routes
: preview_photo_url and preview_photo_path
ROR Lab.
20. More RESTful
Actions
• Collection Routes
resources :photos do
collection do
get 'search'
end
URL : /photos/search with GET
Named Routes
: search_photos_url and search_photos_path
ROR Lab.