加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – redirect_to编辑

发布时间:2020-12-16 21:16:34 所属栏目:百科 来源:网络整理
导读:我的应用程序中有一个很长的表单,所以我设置了一个_new_form.html.erb,它在我的new.html.erb中呈现.在用户更新此表单并传递一些基本验证后,我希望将它们重定向到edit.html.erb,后者呈现完整的表单,即_new_form.html.erb. 我确定这是基本的东西,但我不知道该
我的应用程序中有一个很长的表单,所以我设置了一个_new_form.html.erb,它在我的new.html.erb中呈现.在用户更新此表单并传递一些基本验证后,我希望将它们重定向到edit.html.erb,后者呈现完整的表单,即_new_form.html.erb.

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

我已经尝试使用以下内容更新我的控制器中的创建操作,但我现在在哪里.

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

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读