Reputation: 1715
I have one action which will include the .id for a vendor class through link_to.
That action which is a modification of the new() for a different controller for Reviews needs to pass both the value of the ID from the URL and the session[:user_id] into the database.
How can I grab the value of the vendor.id? Is it possible to not pass it through the URL and place it in the flash instead?
do I use a hidden value to pass the session[:user_id]?
Upvotes: 0
Views: 907
Reputation: 3639
If you're passing parameters between controllers, you should usually pass it as a parameter.
<%= link_to "Link to other controller", other_path(@other, :some_param => param_value) %>
In the action you're linking to (here it's SHOW), you'll be able to access :some_param as params[:some_param].
From forms, go ahead and include a hidden field (as long as you're checking to see if it's valid later on, since a user could submit anything).
Either way, don't use the flash to store session state - the flash is for user messages only.
Upvotes: 0
Reputation: 12157
I assume you can access it as params[:id]
from the controller action? If so, you should be able to access it as params[:id]
in the View. Ditto for session[:user_id]
.
Edit: I think I may have misunderstood your question. Are you asking about posting the id back through the form? Or possibly not having the id in the url?
Upvotes: 1