小编nei*_*led的帖子

为什么render方法在编辑后更改单个资源的路径?

好的,所以我有一个用户 has_one 模板,我想要的页面基本上只是模板的编辑视图。

我有:

class TemplatesController < ApplicationController
  def edit
    @template = current_user.template
  end

  def update
    @template = current_user.template
    if @template.update_attributes(params[:template])
      flash[:notice] = "Template was successfully updated"
    end
    render :edit 
 end
Run Code Online (Sandbox Code Playgroud)

结束

现在,“问题”是当我调用render:edit时,实际上我最终在/template.1而不是/ template / edit上,这正是我所期望的。显然,如果我调用redirect_to:edit,那么我会得到预期的路径,但是如果有的话,我会放宽对象错误。

有一个更好的方法吗?

谢谢!!

controller ruby-on-rails render ruby-on-rails-3

5
推荐指数
1
解决办法
1222
查看次数