Ruby on rails RoR NoMethodError学分中的错误#新
你好, 我正在围绕构建一个简单的RoR应用程序做家庭作业,但遇到了以下问题: 我创建了一个名为“信用”的脚手架,以及用户和信用模型之间的关系: 这是我的文件 credit.rbRuby on rails RoR NoMethodError学分中的错误#新,ruby-on-rails,ruby,Ruby On Rails,Ruby,你好, 我正在围绕构建一个简单的RoR应用程序做家庭作业,但遇到了以下问题: 我创建了一个名为“信用”的脚手架,以及用户和信用模型之间的关系: 这是我的文件 credit.rb class Credit < ActiveRecord::Base attr_accessible :amount, :user_id belongs_to :user belongs_to :merchant end class-Credit
class Credit < ActiveRecord::Base
attr_accessible :amount, :user_id
belongs_to :user
belongs_to :merchant
end
class-Credit
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
class用户
尝试使用以下表单创建新的信用分录时:
<%= 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 %>
我得到以下错误,
学分中的命名错误#新
显示/Users/andreucasadella/rails#u projects/monedero/app/view credits/_form.html.erb,其中第6行出现:
未定义的方法“用户id”#
有什么想法吗?您的信用模型是否有
用户id
列?我建议打开Rails控制台,创建信用对象,然后查看内部。Pry和Pry debugger很适合这种类型的东西,因为Pry允许您“cd”到对象中并查看其所有属性。是,信用等级