我正在尝试添加或删除嵌套的 has_many 对象,如下所示
class Question < ActiveRecord::Base
has_many :comments
end
= form_for @question, :url => {:action => "create"} do |f|
= f.label :name
= f.text_field :name
#comments
= link_to 'Add Comment", add_comment_question_path, method: :get
= f.submit
:javascript
$('#add_comment').click(function() {
$('#comments').append("#{escape_javascript(render(:partial => "comment"))}");
});
在我的 _comment.html.haml
= fields_for @question.comments do |c|
= c.label :msg
= c.text_field :msg
在我的控制器中
def add_comment
@question.comments << Comment.new
end
在路线.rb
resources :questions do
get :add_comment, :on => :member
end
但是我在加载时遇到路由错误question/new.html.haml
。我也跑来rake routes
获取正确的指定网址。为什么我会收到此错误?