Rails has_many更新没有发生错误的url

时间:2017-11-25 18:26:42

标签: ruby-on-rails database oop

尝试更新属于帖子的回复后,我没有收到任何错误。但更新后没有任何事情发生 - 值不会改变。

这是我正在使用的表单

form_with(model: @reply, url: [Comment.find(params[:id]), @reply]) do |form|

传递给页面的参数。命名不是很方便,但id是comment.id,comment_id是回复id。而且我不确定这两个人在什么时候被交换了

Parameters: {"comment_id"=>"75", "id"=>"60"}

我注意到的是链接似乎是错误的:

http://localhost:3000/comments/75/replies/60/edit

正如我所说,评论ID为60,回复ID为75,所以我假设它看起来像:

http://localhost:3000/comments/60/replies/75/edit

控制台中没有错误,当我运行rails c Reply.last时根本没有修改+ updated_at没有被更改。

回复控制器 - 更新

def update
  respond_to do |format|
    if @reply.update(reply_params)
      format.html {redirect_to @comment, notice: 'Reply was successfully updated.'}
      format.json {render :show, status: :ok, location: @reply}
    else
      format.html {render :edit}
      format.json {render json: @reply.errors, status: :unprocessable_entity}
    end
  end
end

我还观察到,如果我在更新中添加代码行if语句将更新所需注释的所有回复

 @comment.replies.update(reply_params)

0 个答案:

没有答案