Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliot-nelson/8133418 to your computer and use it in GitHub Desktop.
Save elliot-nelson/8133418 to your computer and use it in GitHub Desktop.
# Don't do this...
my_url = @thing.new_record? ? new_thing_path : thing_path(@thing)
# Do this...
my_url = polymorphic_path(@thing)
# Especially useful for cases where you need to change the namespace or add extra params...
<%= form_for @thing %>
# Generates /things or /things/<id>
<%= form_for @thing, :url => polymorphic_path([:admin, @thing], :anchor => 'contact_form') do |f| %>
# Generates /admin/things#contact_form or /admin/things/<id>#contact_form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment