【问题标题】:redirect_to edit重定向到编辑
【发布时间】:2013-03-23 04:54:55
【问题描述】:

我的应用程序中有一个很长的表单,所以我设置了一个_new_form.html.erb,它在我的new.html.erb 中呈现。在用户更新此表单并通过一些基本验证后,我希望他们被重定向到呈现完整表单的edit.html.erb,即_new_form.html.erb

我确定这是基本的东西,但我不知道该怎么做。

我已尝试使用以下内容更新我的 Contoller 中的 Create 操作,但我现在知道了。

  def create
    @location = Location.new(params[:location])
      #redirect_to :action => "edit"

    respond_to do |format|
      if @location.save
        format.html { redirect_to edit_location_path(:id), notice: 'Location was successfully created.' }
        format.json { render json: @location, status: :created, location: @location }
      else
        format.html { render action: "new" }
        format.json { render json: @location.errors, status: :unprocessable_entity }
      end
    end
  end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 redirect controller routes


    【解决方案1】:

    您正在尝试重定向到edit_location_path(:id)。符号:id 不是您想在此处传递的。您想要位置的 id 或位置本身:redirect_to edit_location_path(@location)

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      相关资源
      最近更新 更多