Ahmad Z. Tibi
Ahmad Z. Tibi

Reputation: 429

rails edit helper method

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

Answers (2)

Serge Balyuk
Serge Balyuk

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

Dave Newton
Dave Newton

Reputation: 160251

A movie has an id, used by the helper to construct the route string.

Upvotes: 0

Related Questions