我有两个模型评论和程序。我得到这个错误。
我的 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
我也尝试过使用build而不是create。
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
programme.rb
class Programme < ActiveRecord::Base
attr_accessible :biography, :broadcastTime, :description, :title
# Associations
has_many :comments, :dependent => :destroy
end
comment.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
不确定我哪里出错但我会感激一些帮助。
答案 0 :(得分:1)
你的程序拼写有误,首先使用@programmme(3m),然后使用@programme。