undefined method
当我只是尝试查看表单(不提交)时,我有一个 simple_form_for new_comment 导致浏览器中出现comments_path'` 错误
_form.html.slim
= simple_form_for new_comment, :remote => true do |f|
这是部分的,所以传递的局部变量来自hacks脚手架的显示页面
show.html.slim - 黑客
= render partial: "comments/form", locals: { new_comment: @new_comment } if user_signed_in?
我在 hacks 控制器中定义了@new_comment
hacks_controller.rb
def show
@hack = Hack.find(params[:id])
@comments = @hack.comment_threads.order('created_at DESC')
@new_comment = Comment.build_from(@hack, current_user.id, "") if user_signed_in?
#build_from is a method provided by the acts_as_commentable_with_threading gem
end
为什么 new_comment 要路由到 comments_path?我什至没有提交表格。
路线.rb
root 'hacks#index'
concern :commentable do
resources :comments, only: [:create, :update, :destroy]
end
resources :hacks, concerns: [:commentable]
resources :users
devise_for :users, :skip => [:sessions, :registration]
devise_for :user, :path => '', :path_names => { :sign_in => "login",
:sign_out => "logout",
:sign_up => "register",
:account_update => "account-settings" }