【发布时间】:2016-02-17 18:37:18
【问题描述】:
我正在尝试通过提交表单为每个评论更新一个简单的按钮。这是我的查看代码:
<% @comments.each do |comment| %>
<%= form_for comment, url: article_comment_path(comment.article, comment), method: :patch do |f| %>
<%= hidden_field_tag :update_time, Time.now %>
<%= f.submit "Confirm" %>
<% end %>
<% end %>
评论控制器更新操作代码:
def update
@article = Article.friendly.find(params[:article_id])
@comment = @user.comments.find(params[:id])
if @comment.update(comment_params)
redirect_to @comments
else
render article_comments_path(@article)
end
end
private
def comment_params
params.require(:comment).permit(:date, :note)
end
使用上面的代码,我收到了这个错误:
参数丢失或值为空:comment - 错误突出显示私有声明中的 params.require 行
【问题讨论】:
-
嗨,如果我的回答有用,请考虑选择它作为接受的答案,这就是社区的运作方式......
-
嗨,我还在等你把我的回答标记为已接受,我花了一些时间回答你...谢谢
标签: ruby-on-rails-4 form-for nested-resources