0
저는 Rails에 처음 접했고이 문제를 우연히 발견했습니다. 나는 그것이 당신에게 비교적 간단하게 될 것이라고 추측하고 있습니다. 나는 User라는 모델을 가지고 있으며,이 모델 안에는 모든 사용자 속성이 있습니다. 나는 또한 list라는 모델을 만들었고 이제는하고 싶다. 지금은 내가 다음Ruby on Rails 프로젝트에서 정의되지 않은 오류
irb(main):011:0> sample.Lists.new
NoMethodError: undefined method `Lists' for #<User:0x4146750>
아래는 내 모델 파일입니다이 오류를 얻을 수 (모든 콘솔에서 일어나고있는) 다음과 같은 일을
sample = User.create(#attributes here)
newlist = sample.List.create(#attributes here)
을 구입 메소드를 호출 사용자로부터 만들려고하고 있어요 사용자 및 목록
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# firstName :string(255)
# middleName :string(255)
# lastName :string(255)
# email :string(255)
# facebookexternalId :integer
# userType :integer
# gender :string(255)
# description :string(255)
# location :string(255)
# image :string(255)
# password :string(255)
# notificationId :string(255)
# disabled :boolean
# disabledNotes :string(255)
# city :string(255)
# country :string(255)
# joinDate :string(255)
# created_at :datetime not null
# updated_at :datetime not null
class User < ActiveRecord::Base
attr_accessible :firstName, :middleName , :lastName ,:email , :facebookexternalId, :gender , :description, :location , :image , :city, :country, :disabled
email_regex= /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :firstName , :presence =>true,
:length => {:maximum => 45}
validates :lastName , :presence =>true,
:length => {:maximum => 45}
validates :email , :presence =>true,
:format =>{:with => email_regex},
:uniqueness => {:case_sensitive => false}
validates :description, :length => {:maximum => 140}
has_many :lists
end
목록
# == Schema Information
#
# Table name: lists
#
# id :integer not null, primary key
# name :string(255)
# user_Id :integer
# active :boolean
# type :string(255)
# description :string(255)
# roughList :boolean
# created_at :datetime not null
# updated_at :datetime not null
#
class List < ActiveRecord::Base
belongs_to :user
end
당신은 거기에 목록을 사용한다
너 더 빨랐어. ; o) –
정말 고마워!......... 당신은 실제로 나에게 내가 만들고 있었던 또 다른 실수를 깨닫게했다. 주 사용자 테이블의 ID에 외래 키 제약 조건을 적용하지 않았습니다. 다시 한 번 감사드립니다! –