2

i've got model with:

class Product < ActiveRecord::Base
  attr_accessible :category, :description, :img_url, :name, :price, :quantity, :tags

  serialize :tags, Hash
end

and try to make form for it

<%= form_for @product do |f| %>
    <%= f.label :"tags[:condition]_new", "new" %>
    <%= f.radio_button :"tags[:condition]", "New", checked: true %>
    <%= f.radio_button :"tags[:condition]", "Used" %> 
<% end %>

unfortunately it rails raise

undefined method `tags[:condition]' for #Product:0x007fd26d965810> <%= f.radio_button :"tags[:condition]", "Used" %> <-- ONLY FOR 2ND LINE. first is okey. WHY?!

and I can't figure out why its trying to put method on it. Has anyone idea how to make proper field for hash value? + Why it fails only on 2nd f.radio_button and i passes first one?

0

1 Answer 1

2

This is because you are not setting any value for 2nd radio button, try this and it will work fine.

<%= f.radio_button :"tags[:condition]", "Used", checked: false %>

As if you will not pass any value, then FormHelper class will call 'name[:condition]' method on @product to get its corresponding value, though there is no method defined in the model it raises exception.

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.