嗨, 我在建筑物周围做了一个简单的RoR应用程序,并遇到以下问题: 我创建了一个名为“Credit”的Scaffold,以及User和Credit模型之间的关系: 这是我的文件
credit.rb
class Credit < ActiveRecord::Base
attr_accessible :amount, :user_id
belongs_to :user
belongs_to :merchant
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :profile_name
# attr_accessible :title, :body
has_many :statuses
has_many :merchants
has_many :credits
def full_name
first_name + " " + last_name
end
end
尝试使用以下格式创建新的信用条目时:
<%= simple_form_for(@credit) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :amount %>
<%= f.input :user_id, collection: User.all %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
我收到以下错误
Credits中的NoMethodError#new
显示/ Users / andreucasadella / rails_projects / monedero / app / view credits / _form.html.erb第6行引发:
#
的未定义方法`user_id'有什么想法吗?