Ruby on Rails
Sunday, August 18, 2013
Hello,
I am developing a project using rails 4.0.0 and I came up to a question about nested _path helper.
In my routes I have something like this:
namespace :admins do
resources :educators, shallow: true do
resources :users
end
end
The url to show up the view to create a new user for an educator (e.g. 17) is "/admin/educators/17/users".
This will show up the following view:
<%= form_for @user_invite, url: admin_educator_users_path do |f| %>
<%= f.text_field :email %>
<%= f.text_area :message %>
<%= f.submit "Invite" %>
<% end %>
Nothing special and works as expected. The @user_invite is an ActiveModel instance a can be ignored for my question. My question refers to the call of the _path helper "admin_educator_users_path" without any arguments. Almost all documentation and the rails guides always call the _path helper like:
admin_educator_users_path(@educator)
It seems like the _path helper is clever enough to extract the missing "educator_id" from the url/params hash.
In the view both invocations:
admin_educator_users_path(@educator)
admin_educator_users_path()
output this:
/admin/educators/17/users
I can even call:
new_admin_educator_user_path()
and the outputs is as expected:
/admin/educators/17/users/new
Is this a feature or an unexpected behavior - I am asking because it is not explicitly mentioned in the rails guides (at least I did not found it).
Any help would be really appreciated.
Regards,
Jan
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/72947af7-2bde-43e8-baa3-ae123302eada%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment