class User < ActiveRecord::Base
has_many :ties, dependent: :destroy
has_many :albums, through: :ties
end
class Album < ActiveRecord::Base
has_many :ties, dependent: :destroy
has_many :users, through: :ties
end
class Tie < ActiveRecord::Base
belongs_to :user
belongs_to :album, dependent: :destroy
end
K...所以,当尝试从 AlbumsController#Create 操作创建专辑时:
def create
@album = current_user.albums.build(params[:album]) #error is on this line
if @album.save
flash[:success] = "#{@album.description} created!"
redirect_to @album
else
flash[:error] = 'Looks like something was invalid with that album. Try again.'
redirect_to albums_path
end
end
我得到uninitialized constant User::Ty
。我认为 railsTie
与Ty
. 任何想法?我可以强制使用某些名称en.yml
吗?