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