How to include params in a REST 'NEW' link
I have a REST resource called 'requests' as follows:
resources :requests, :only => [:new, :create, :destroy]
I have a page where the User selects a Group to join. This means they want to create a 'NEW' request.
I want to pass the ID of the group along with the link but its a REST resource.
<%= link_to "Join", new_request_path %>
But how can I add an id to th开发者_如何学Pythonis link?
Rails 3.
A simple way to do it would be to (assuming the group you join has id as '5')
link_to "Join" , new_request_path(:group_id => '5')
and access it in the controller action as params[:group_id].
But this would not be very RESTful or Rails 'ish'. If you can model it as if requests belong to a group . then you should be able to do (assuming you want to join @group):
link_to "Join" , new_group_request_path(@group)
Read up a little about Nested Resources and nesting routes in rails 3. There are so many articles there if you google for it.
Of course the above would force you to change the way your have designed your models. But then maybe thats good!
精彩评论