【发布时间】:2015-09-24 04:17:59
【问题描述】:
每个都有帖子和 cmets 表格。 我正在尝试通过表单为每个帖子添加评论。这一切都发生在同一个页面上。
查看文件代码:
<% @posts.each do |post| %>
<%=post.title%>
<%=post.text%>
<%post.comments.each do |com|%>
<h3> <%=com.content%> </h3>
<%end%>
<%= form_for post.comments.build do |f| %>
<p>comments:</p>
<%= f.text_area :content, size: "12x12" %>
<%=f.submit%>
<% end %>
<% end %>
评论控制器代码:
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params)
@comment.save
redirect_to root_path
end
该程序似乎无法访问 :post_id。 我的模型中有所有关联,我的数据库架构中有 :post_id。
【问题讨论】:
标签: ruby-on-rails ruby activerecord