Strange Rails Routing: Two IDs Swap Nested Resources

I have the following routing configured in my application (forms belong to the site):

map.resources :sites do |site| 
 site.resources :forms
end 

However, when I try to go to the path for editing (or such) for the form using helpers (e.g.

edit_site_form_path(form)

or

<%= link_to 'Show', [:site, form] %>

my URLs are issued with a changed identifier (/ sites / 5 / forms / 1), where 5 is the form identifier and 1 is the site identifier. This is from page / sites / 1.

Reference (?)

+3
source share
1 answer

edit_site_form_path : site_id form_id. form_id. - , - , site. - form_id.

:

 edit_site_form_path(form.site, form)

( Form, belongs_to :site)

+4

Source: https://habr.com/ru/post/1706600/


All Articles