だから私はAnimal
モデルとモデルを持っていUser
ます。AUser
は多くの を持つことができますAnimals
。ユーザーにDevise Gemを使用しています。0
現在、ユーザーと動物の間には何の関係もありませんが、ユーザーが 1つ以上の動物を所有できるようにしたいと考えています。
これは私がこれまでに追加したものです:
app/models/animal.rb
:
class Animal < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user # not sure if this is needed
attr_accessible :name, :age
end
app/models/user.rb
:
class User < ActiveRecord::Base
has_many :animal
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
end
移行を記述する必要がありますか? 他に追加する必要があるものはありますか? 上記は正しいですか?
ありがとう。