Reputation: 429
I want to ask in rails about URI helpers, in action edit for example:
we used Helper method: edit_movie_path(@movie)
, (suppose @movie is instance variable)so the corresponding Restful Route will be
GET /movies/id/edit
I confused about how it passes id! as we passed @movie (we did not pass id)?
Upvotes: 1
Views: 182
Reputation: 3462
Rails leverages polymorphism. Every object gets to_param
method (here). ActiveRecord::Base
overrides it to return record id
, see these api docs. Url helpers then rely on the fact that everything can be turned into param with to_param
Upvotes: 2
Reputation: 160251
A movie has an id, used by the helper to construct the route string.
Upvotes: 0