1
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
ķ......所以,當試圖創建相冊,從AlbumsController#創建行動:NameError與has_many_through表
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
。我認爲鐵軌Tie
與Ty
混淆。任何想法?我可以強制從en.yml
某些名字?
是有一些原因,你不建議使用'irregular',瑞安?這是否僅適用於默認規則不適用於任何方向的情況? –
@PeterAlfvin:是的,沒錯。 「領帶」的單數將是「領帶」,但如果你將「領帶」複數化,你總會得到「領帶」。 –
'C:/railsinstaller/ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/inflector/inflections.rb:166:in'inflections':錯誤的參數個數(1爲0)(ArgumentError)'當試圖在那之後啓動服務器時。 – Dudo