我试图通过提交表单来更新每个评论的简单按钮。这是我的看法代码:Rails,嵌套资源,更新操作
<% @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
通过上面的代码中,我得到这个错误:
参数是丢失或为空值:评论 - 错误突出了私人声明中的params.require行
嗨,如果我的答案是有用的,请考虑选择它作为接受的答案,这就是社区的工作原理... – SsouLlesS
嗨,我仍然在等待你来标记我的答案被接受,我花了一些时间回答你...谢谢 – SsouLlesS