0
我的場景:電影有評論,評論有評論。Rails3路由錯誤
電影模式:
has_many :reviews
審查模式:
has_many :comments
belongs_to :movie
評價模型:
belongs_to :review
路線:
resources :movies do
resources :reviews do
resources :comments
end
end
條
評論控制器:
def create
@movie = Movie.find(params[:movie_id])
@review = Review.where(:movie_id => @movie.id)
@comment = @review.comments.create(params[:comment]) // Line 5
redirect_to movie_path(@movie)
end
評論觀點:
<%= form_for([@movie, r, r.comments.build]) do |f| %>
<div class="field">
<%= f.text_area :body %>
</div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<% end %>
,我得到的是錯誤:
NoMethodError (undefined method `comments' for #<ActiveRecord::Relation:0x007ff5c5870010>):
app/controllers/comments_controller.rb:5:in `create'
有人能告訴我什麼,我做錯了什麼?
在此先感謝..
完美的作品..(我剛剛接受了另一個問題的答案,它讓我等待4分鐘)..將在4 ..後接受.. ..非常感謝 – Ari53nN3o 2011-12-14 10:48:54