Rob
Rob

Reputation: 1855

hidden_field_tag value doesn't pass to the right params hash

I want key_type to pass in the category_item_value params hash on the form submit but it passes outside the hash.

Parameters: {"utf8"=>"✓", "authenticity_token"=>"H0p7vNzcl0r0KNPWTHOGgaem0ngpsjIq5DmXZ8A7woZOztECkC9lv5cBH0CloH4ivEL0VtU5uDMPZTJQZQDjOQ==", "category_item_value"=>{"key"=>"this-Is-AttRibute-Page", "value"=>"okkkkkkkk"}, "key_type"=>"", "commit"=>"Submit",...

Here is the form

 <%= form_for([@category_item, @category_item_value], url: create_category_item_value_path, method: :post) do |f|  %>
  <%= render 'shared/error_messages', object: f.object %>

   <%= f.label :attribute, "Pick a key to add an attribute to." %> 
   <%= f.select :key, options_for_select(@key_names) %>

   <%= hidden_field_tag :key_type, 2 %>

   <%= f.label :value %> 
   <%= f.text_field :value %>

   <%= f.submit "Submit" %>

 <% end %>

I need the hidden field to pass inside the category_item_value hash. Why isn't it happening?

Also I know hidden fields are unsafe, users can change the key_type on other forms easily, so its not a problem if they try and be mr. hackety hack and change it on this one. Its just hidden for convenience.

Upvotes: 0

Views: 627

Answers (1)

Rob
Rob

Reputation: 1855

There were 2 problems.

  1. hidden_field_tag was supposed to be f.hidden_field. This adds it to the right hash but throws an error.
  2. to fix the error I replaced :key_type, 2 with :key_type, :value => 2

Upvotes: 1

Related Questions