0
我有两个模型的评论和程序。我得到这个错误。NoMethodError评论控制器 - Rails 3.2
我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
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
不知道我哪里错了,但我会感谢一些帮助。
非常感谢@Vysash。 – Benjamin 2013-02-08 13:02:12
@Vezu你仍然要小心拼写,你现在拼错我的名字:P – 2013-02-08 13:10:31
对不起@Vysakh。 :) – Benjamin 2013-02-08 13:57:33