25 Sep '13, 3am

楽だけどわかる書き方しないと再利用性が〜〜〜

Polymorphic URL helpers are methods for smart resolution to a named route call when given an Active Record model instance. They are to be used in combination with ActionController::Resources. These methods are useful when you want to generate correct URL or path to a RESTful resource without having to know the exact type of the record in question. Nested resources and/or namespaces are also supported, as illustrated in the example: polymorphic_url([:admin, @article, @comment]) results in: admin_article_comment_url(@article, @comment) Usage within the framework Polymorphic URL helpers are used in a number of places throughout the Rails framework: url_for , so you can use it with a record as the argument, e.g. url_for(@article) ; ActionView::Helpers::FormHelper uses polymorphic_path , so you can write form_for(@article) without having to specify :url parameter for the form a...

Full article: http://api.rubyonrails.org/classes/ActionDispatch/Routing...

Tweets