Download presentation
Presentation is loading. Please wait.
Published byKristian Haynes Modified over 8 years ago
1
Routes Carol Wolf Computer Science
2
RESTful Architecture Rails uses REST-style architecture: representation state transfer resources :courses in routes.rb translates to: courses GET /courses(.:format) {:action=>"index", :controller=>"courses"} POST /courses(.:format) {:action=>"create", :controller=>"courses"} new_course GET /courses/new(.:format) {:action=>"new", :controller=>"courses"} edit_course GET /courses/:id/edit(.:format) {:action=>"edit", :controller=>"courses"} course GET /courses/:id(.:format) {:action=>"show", :controller=>"courses"} PUT /courses/:id(.:format) {:action=>"update", :controller=>"courses"} DELETE /courses/:id(.:format) {:action=>"destroy", :controller=>"courses"}
3
RESTful Architecture – from the textbook index Returns a list of the resources. create Creates a new resource from the data in the POST request, adding it to the collection. new Constructs a new resource and passes it to the client. This resource will not have been saved on the server. You can think of the new action as creating an empty form for the client to fill in. show Returns the contents of the resource identified by params[:id]. update Updates the contents of the resource identified by params[:id] with the data associated with the request. edit Returns the contents of the resource identified by params[:id] in a form suitable for editing. destroy Destroys the resource identified by params[:id].
4
Generating a controller Generating a controller creates routes (with gets) for each of the methods in the controller. rails generate controller librarian index list_books find_book This produces a controller with three methods and adds three routes to the routes.rb file. Two of the routes must be changed to posts. get "librarian/index " post "librarian/list_books " post "librarian/find_book" If a view is sent with a submit button, its route must be a post.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.