samedi 29 août 2015

Quirky Ruby on Rails Syntax

Background: Novice rails developer here learning from Michael Hartl's Ruby on Rails Tutorial (http://ift.tt/1xlbKQQ) in which you develop a basic twitter-like app with a User model and Post model. The users routes are generated from what I understand is the common method of inserting the following into the routes.rb file:

resources :users

Question: I don't understand why when you use:

redirect_to @user

rails sends that request to UsersController#show, but it does so by calling user_url(@user) via:

get "/users/id" => "users#show"

Where does the singular ("user") in user_url come from in the code immediately above? I would think user-url should be users_url or users_path (as I see come up in some places). Just trying to figure out where this singular is coded into rails.

Thanks!

Aucun commentaire:

Enregistrer un commentaire