【发布时间】:2011-10-17 21:16:22
【问题描述】:
在浏览器地址栏中我有http://localhost:3000/comment/index?post_id=6,我可以访问索引中的post_id,但是当尝试在创建操作中创建评论/帖子时,它说在日志中找不到没有帖子ID的帖子。什么是在这里继续吗?提前谢谢你。
评论控制器:
def index
@post=Post.find(params[:post_id])
end
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.save
respond_with( @comment, :layout => !request.xhr? )
end
comments/index查看:
<%= form_for :comment, :remote => true,
:url => { :controller => "comments",
:action => "create"
},
:html => { :id => 'new-comment'} do |f|
%>
<%= f.hidden_field :post_id, :value => @post.id %>
<%= f.text_area :body %>
<%= f.submit "post" %>
<% end %>
在日志中:
Started POST "/comments" for 127.0.0.1 at 2011-10-17 14:06:36 -0700
Processing by CommentsController#create as JS
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"cxQm2K2xwsyw0DY2XLNvkcMQI+wM96LpEENbfQqxu5c=",
"comment"=> {"post_id"=>"6", "body"=>"This is the comment"},
"commit"=>"post"}
Completed 404 Not Found in 23ms
ActiveRecord::RecordNotFound (Couldn't find Post without an ID):
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routes ruby-on-rails-3.1