Ruby on rails 为什么Rails会忽略我提交表单的参数?
我正在尝试在Rails 3中提交一个simplel表单,与acts_as_可注释插件一起使用Ruby on rails 为什么Rails会忽略我提交表单的参数?,ruby-on-rails,ruby-on-rails-3,forms,Ruby On Rails,Ruby On Rails 3,Forms,我正在尝试在Rails 3中提交一个simplel表单,与acts_as_可注释插件一起使用 #new_comment_box #comment_input_box = form_for :comment, :url => comments_path(commentable.class.to_s.underscore, commentable.id), :html => {:id => "new_comment"}, :remote => true do |
#new_comment_box
#comment_input_box
= form_for :comment, :url => comments_path(commentable.class.to_s.underscore, commentable.id), :html => {:id => "new_comment"}, :remote => true do |f|
#share-input
= f.text_area :comment, :id => 'comment-input', :'data-text' => "Comment on this review...", :placeholder => "Comment on this review..."
.cancel
.clear
= f.submit 'Comment', :id => 'item-comment-submit', :class => "button"
.clear
我的注释模型有一个“Comment”文本属性,并且
我的控制器非常简单:
class CommentsController < ApplicationController
before_filter :load_commentable
def create
pp params[:comment]
@comment = @commentable.comments.build(params[:comment])
@comment.user = current_user
respond_to do |format|
if @comment.save
format.html {render :partial => 'comments/comment', :locals => {:commentable => @commentable, :comment => @comment}}
end
end
end
def destroy
@comment = @commentable.comments.find(params[:id])
@comment.destroy
respond_to do |format|
format.json {render :json => params[:id]}
end
end
protected
def load_commentable
@commentable = params[:commentable_type].camelize.constantize.find(params[:commentable_id])
end
end
但是,当我尝试提交此表单时,rails日志未检测到任何内容被占用:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"cXgddasdMMV38Ye/fIVVrkdfsdpH7iZE/iFYsdfsdfz4oO2Szs=", "comment"=>{"comment"=>""}, "commit"=>"Comment", "commentable_type"=>"item", "commentable_id"=>"252"}
此外,从firebug看来,请求甚至没有从页面发送评论
有人能告诉我我做错了什么,为什么这不起作用
出于某种原因,谢谢你。。它不喜欢将textarea id作为“注释输入”。当我把它改为“评论”时,它起了作用。。。我仍然希望你能解释一下为什么这样做会失败,这很好 您不需要给它一个自定义的
id
属性,因为它已经有了一个基于字段名称的名为comment\u comment
的属性。最好不要搞砸了
不幸的是,我不知道为什么它不接受这个命名奇怪的参数。代码可能位于应用程序中的
rails.js
或jquery\u ujs.js
文件中。谢谢,顺便问一下,您是否知道它在rails代码库的何处生成这些id、类名?我想通读一遍,以了解背后的规则it@Noli:通常为“[对象\类\名称]\[字段\名称]”。我不知道它在Rails的何处生成,请查看text\u字段
或标签
方法的代码。
POST /:commentable_type/:commentable_id/comments(.:format) {:action=>"create", :controller=>"comments"}
Parameters: {"utf8"=>"✓", "authenticity_token"=>"cXgddasdMMV38Ye/fIVVrkdfsdpH7iZE/iFYsdfsdfz4oO2Szs=", "comment"=>{"comment"=>""}, "commit"=>"Comment", "commentable_type"=>"item", "commentable_id"=>"252"}