0

I want to pass a variable to a partial, then from the partial through a form to the controller, am I doing that correctly? The variable is called item_id.

The partial form entry + variable:

<%= form_tag contribute_stripe_path, method: :post do %>
...
<%= hidden_field_tag item_id %>
...

The controller

@item_id = params[:item_id]
item = Count.find(@item_id)
... 
item.update_attribute(:value, new_value) 

Routes

post '/contribute', to: 'counts#stripe', as: 'contribute_stripe'
3
  • Well, this seems correct. Don't forget about the condition to check whether an item exists. Also I believe this should be: hidden_field_tag 'item_id', item_id Commented Oct 20, 2014 at 8:41
  • Are you facing any issues(post the error part), also post the html code from where the partial is being called. The current flow looks fine. Commented Oct 20, 2014 at 10:29
  • The item_id was not passing, @bodrovis and Fer's answer worked Commented Oct 20, 2014 at 15:59

1 Answer 1

1

Posting the error usually helps.

What I see is the way you are defining the field is wrong.

<%= hidden_field_tag :item_id, item_id %>

The first param sets the field name, and the second one, its value (if the item_id variable is defined... if not you will get an error)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.