AFG
AFG

Reputation: 1715

how do I pass an ID from the URL into a form_tag in Ruby?

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.

Upvotes: 0

Views: 907

Answers (2)

Raphomet
Raphomet

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

Matt Grande
Matt Grande

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

Related Questions