Routes - PowerPoint PPT Presentation

About This Presentation
Title:

Routes

Description:

Routes Carol Wolf Computer Science RESTful Architecture Rails uses REST-style architecture: representation state transfer resources :courses in routes.rb translates ... – PowerPoint PPT presentation

Number of Views:189
Avg rating:3.0/5.0
Slides: 5
Provided by: CarolE261
Learn more at: http://csis.pace.edu
Category:
Tags: routes

less

Transcript and Presenter's Notes

Title: Routes


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)
  • actiongt"index", controllergt"courses"
  • POST /courses(.format)
  • actiongt"create", controllergt"courses"
  • new_course GET /courses/new(.format)
  • actiongt"new", controllergt"courses"
  • edit_course GET /courses/id/edit(.format)
  • actiongt"edit", controllergt"courses"
  • course GET /courses/id(.format)
  • actiongt"show", controllergt"courses"
  • PUT /courses/id(.format)
  • actiongt"update", controllergt"courses"
  • DELETE /courses/id(.format)
  • actiongt"destroy", controllergt"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 paramsid.
  • update
  • Updates the contents of the resource identified
    by paramsid with the data associated with the
    request.
  • edit
  • Returns the contents of the resource identified
    by paramsid in a form suitable for editing.
  • destroy
  • Destroys the resource identified by paramsid.

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.
Write a Comment
User Comments (0)
About PowerShow.com