Rails - Symbol not generated when using belongs_to
I have a model Tran that is setup in the following way:
class Tran < ActiveRecord::Base
has_many :transaction_users, :dependent => :destroy, :class_name => 'Transacti开发者_如何转开发onUser'
belongs_to :submitting_user, :class_name => 'User'
belongs_to :buying_user, :class_name => 'User'
Now, in my view, I am trying to get access to :submitting_user_id
, since I have set up the foreign key, but rails yells at me and says it can't find the symbol. Shouldn't I have access to it? If not, how can I get access?
View:
<%= nested_form_for(@tran, :url => trans_path) do |f| %>
<div class="field">
<%= f.label "Buyer" %>
<%= f.select :submitting_user_id, options_from_collection_for_select(User.active_users, 'id', 'full_name') %>
</div>
Error:
undefined method `submitting_user_id' for #<Tran:0x7f6713032fb0>
This isn't automatically generated for you, you must have a submitting_user_id
field added to your table by a migration.
精彩评论