0

I have a form with hidden field:

<%= f.hidden_field(:equipment_id, :value => " ") %>

The value for this field is submitted via js. So that my generated html looks like this:

<input value="2" type="hidden" name="programm[equipment_id]" id="programm_equipment_id">

When i submit my form my parameters look like this:

"programm"=>{
  .. some other params ..,
 "equipment_id"=>"2"
}

In my controller's create method I try to assign equipment_id parameter to @programm.equipment_id:

@programm.equipment_id = params[:programm => :equipment_id ]

like that. Where equipment_id is an integer column in database. The problem is that nothing gets assigned. If i try to cast .to_i "0" is being assigned and stored in database. I also tried to do:

@programm.equipment_id = params[:equipment_id ]

But the problem is the same.

1
  • Did you create your controller/model/... by using the rails scaffolder? Commented Apr 7, 2015 at 13:27

3 Answers 3

1

This should do the trick:

@programm.equipment_id = params[:programm][:equipment_id]
Sign up to request clarification or add additional context in comments.

Comments

1

The params are nested. You can access it like this:

@programm.equipment_id = params[:programm][:equipment_id]

Comments

0

for the view like this:-

<%= form_for(@programm) do |f|%>
  <%= f.hidden_field(:equipment_id, :value => " ") %>
<%end%>

Upon form submission the value entered by the user will be stored in params[:programm][:equipment_id] and can be used to access the value.

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.