Form_for with radio_button generated from database-Collection of common programming errors

This would seem easy to do, basically I’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 => :admin
  attr_accessible :email, :password, :password_confirmation, :remember_me

  has_many :trades
  has_many :figures, :through => :trades
  accepts_nested_attributes_for :trades

Class Figure
  attr_accessible :image_url, :name, :series, :figure_id

  has_many :trades
  has_many :users, :through => :trades
  accepts_nested_attributes_for :trades

Class Trade
  attr_accessible :figure_id, :user_id

  belongs_to :user
  belongs_to :figure

The Controller for Trade

def new
  @trade = Trade.new
end

def create
  @trade = current_user.figures.build(params[:trade])
end

The Form for trade


  
    
      # Create a list of figurines radio buttons
       (params[:figure_id] == nil ? false : params[:figure_id]) %>
        # Link the figures thumbnail to the radio button
       "40x58", :alt => figure.name ), :value => "#{figure.id}" %>
   
 

 
   
 

Here’s the parameters

{"utf8"=>"✓",
  "authenticity_token"=>"lo+RWOLxGhPIP1pmJhk9v+vetO7cGEKGY844egaQ6A0=",
  "trade"=>{"figure_id"=>"12"},
  "commit"=>"Create Trade"}

Here’s the problem I’m getting: unknown attribute: figure_id

Why am I receiving this error?

  1. If I understand you correctly, this error should go away if you build a Trade instead of a Figure (you’re just trying to link a figure to a user through a new trade, right?):

    def create
       @trade = current_user.trades.build(params[:trade])
       @trade.save
    end
    

Originally posted 2013-11-09 23:32:31.