我試圖通過提交表單來更新每個評論的簡單按鈕。這是我的看法代碼: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