我有两个模型评论和程序。我得到这个错误。
我的comments_conroller.rb看起来像这样
def create
@programmme = Programme.find(params[:programme_id])
@comment = @programme.comments.create!(params[:comment])
if @comment.save
redirect_to @comment.programme, notice: "Comment has been sent."
else
format.html { redirect_to @comment.programme, notice: "There was an error creating your comment."}
end
end
我也尝试过使用构建而不是创建。
def create
@programmme = Programme.find(params[:programme_id])
@comment = @programme.comments.build(params[:comment])
if @comment.save
redirect_to @comment.programme, notice: "Comment has been sent."
else
format.html { redirect_to @comment.programme, notice: "There was an error creating your comment."}
end
end
程序.rb
class Programme < ActiveRecord::Base
attr_accessible :biography, :broadcastTime, :description, :title
# Associations
has_many :comments, :dependent => :destroy
end
评论.rb
class Comment < ActiveRecord::Base
attr_accessible :email, :location, :message, :name, :requestFor, :song
#Associations
belongs_to :programme
end
我的routes.rb看起来像这样
DigneRadio::Application.routes.draw do
resources :programmes do
resources :comments
end
resources :replays
resources :articles
end
不知道我哪里出错了,但我会很感激一些帮助。