lightbots
lightbots

Reputation: 485

passing variable to partial to controller via a form

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'

Upvotes: 0

Views: 30

Answers (1)

Fer
Fer

Reputation: 3347

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)

Upvotes: 1

Related Questions