不成功的更新呈现:编辑。为什么编辑显示在 :show 路径?

And*_*vey 2 ruby-on-rails

典型的 Rails 更新操作如下所示

def update
  respond_to do |format|
    if @object.update(object_params)
      # success results
    else
      format.html { render :edit }
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

因此,我希望,如果更新不成功,用户将最终到达 path /objects/:id/edit

为什么是实际路径/objects/:id,但显示编辑表单?

这是正常行为,还是此应用程序中发生了奇怪的事情?

编辑

#routes.rb

devise_for :users
resources :objects do
  resources :children, only: [:index, :new, :create]
  member do
    get :customaction
  end
end

#ability.rb
can :create, Object
can :manage, Object, id: @user.object_id
cannot [:index, :destroy], Object
Run Code Online (Sandbox Code Playgroud)

ill*_*ist 5

让我解释,

我希望你在编辑表单中注意到它的样子

<form class="edit_post" id="edit_post_1" action="/posts/1" accept-charset="UTF-8" method="post">
Run Code Online (Sandbox Code Playgroud)

表单数据发布在/posts/1; 这是浏览器命中的用于发送表单数据的 URL。

因此,当您的update任务失败或validation发生任何错误时;您不会重定向 http 请求,而是渲染edit-form并返回到浏览器。浏览器显示表单而不更改web address.

注意:只redirect更改网址,render不会。

如果表单数据提交给/posts/1/edit而不是,您的假设将是正确的/posts/1