我剛創建了評論模型,出於某種原因,我的歌曲提交內容不再顯示在歌曲#索引中。添加新模型後,CRUD不再顯示內容
總之,最初我只有一個帶有典型CRUD功能的歌曲控制器。當我創建一首新歌曲時,它會被張貼並顯示在索引中。但是,創建評論模型後,歌曲不再顯示(或者甚至可能完全被創建)。
我在下面的要點中附上了各種頁面。我會根據要求更新這篇文章並附加任何頁面。
https://gist.github.com/Apane/affe60c5b9d0d33cbaf8
comment.rb
class Comment < ActiveRecord::Base
belongs_to :song
belongs_to :user
validates_presence_of :author_name, :content
end
song.rb
class Song < ActiveRecord::Base
has_many :comments, :dependent => :destroy
belongs_to :user
has_attached_file :track,
:url => "/assets/songs/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/songs/:id/:style/:basename.:extension"
validates_attachment :track, :presence => true
validates :title, length: { minimum: 10 }
validates :bio, length: { maximum: 300 }
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :songs
end
Hav如果您正在創建並未顯示新歌曲,則通過查看控制檯進行檢查。 –
是的,保存由於某種原因返回false :( – Apane101
添加歌曲和評論模型的源代碼的要點,更有可能你已經創建了一個關係,指定一個內部連接,所以沒有評論的歌曲沒有被返回。 – cfeduke