{"id":1148,"date":"2022-08-30T15:13:11","date_gmt":"2022-08-30T15:13:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/form_for-with-radio_button-generated-from-database-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:11","modified_gmt":"2022-08-30T15:13:11","slug":"form_for-with-radio_button-generated-from-database-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/form_for-with-radio_button-generated-from-database-collection-of-common-programming-errors\/","title":{"rendered":"Form_for with radio_button generated from database-Collection of common programming errors"},"content":{"rendered":"<p>This would seem easy to do, basically I&#8217;m using Devise for administrative purposes, so every user signing up can create a product\/figure linked to their account then put up that product for a trade with another user.<\/p>\n<pre><code>Class User\n  rolify\n  :recoverable, :rememberable, :trackable, :validatable\n  attr_accessible :role_ids, :as =&gt; :admin\n  attr_accessible :email, :password, :password_confirmation, :remember_me\n\n  has_many :trades\n  has_many :figures, :through =&gt; :trades\n  accepts_nested_attributes_for :trades\n\nClass Figure\n  attr_accessible :image_url, :name, :series, :figure_id\n\n  has_many :trades\n  has_many :users, :through =&gt; :trades\n  accepts_nested_attributes_for :trades\n\nClass Trade\n  attr_accessible :figure_id, :user_id\n\n  belongs_to :user\n  belongs_to :figure\n<\/code><\/pre>\n<p>The Controller for Trade<\/p>\n<pre><code>def new\n  @trade = Trade.new\nend\n\ndef create\n  @trade = current_user.figures.build(params[:trade])\nend\n<\/code><\/pre>\n<p>The Form for trade<\/p>\n<pre><code>\n  \n    \n      # Create a list of figurines radio buttons\n       (params[:figure_id] == nil ? false : params[:figure_id]) %&gt;\n        # Link the figures thumbnail to the radio button\n       \"40x58\", :alt =&gt; figure.name ), :value =&gt; \"#{figure.id}\" %&gt;\n   \n \n\n \n   \n \n\n<\/code><\/pre>\n<p>Here&#8217;s the parameters<\/p>\n<pre><code>{\"utf8\"=&gt;\"\u2713\",\n  \"authenticity_token\"=&gt;\"lo+RWOLxGhPIP1pmJhk9v+vetO7cGEKGY844egaQ6A0=\",\n  \"trade\"=&gt;{\"figure_id\"=&gt;\"12\"},\n  \"commit\"=&gt;\"Create Trade\"}\n<\/code><\/pre>\n<p>Here&#8217;s the problem I&#8217;m getting: <strong>unknown attribute: figure_id<\/strong><\/p>\n<p>Why am I receiving this error?<\/p>\n<ol>\n<li>\n<p>If I understand you correctly, this error should go away if you build a <code>Trade<\/code> instead of a <code>Figure<\/code> (you&#8217;re just trying to link a figure to a user through a new trade, right?):<\/p>\n<pre><code>def create\n   @trade = current_user.trades.build(params[:trade])\n   @trade.save\nend\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:32:31. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>This would seem easy to do, basically I&#8217;m using Devise for administrative purposes, so every user signing up can create a product\/figure linked to their account then put up that product for a trade with another user. Class User rolify :recoverable, :rememberable, :trackable, :validatable attr_accessible :role_ids, :as =&gt; :admin attr_accessible :email, :password, :password_confirmation, :remember_me has_many [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1148","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1148"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1148\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}