Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect_to edit

I have quite a long form in my app so I've set up a _new_form.html.erb which is rendered in my new.html.erb. After the user updates this form and passes some basic validations I would like them to be redirected to the edit.html.erb which renders the full form, i.e. _new_form.html.erb.

I'm sure this is basic stuff but I can't find out how to do it.

I've tried updating the Create action in my Contoller with the below but I'm getting now where.

i.e.

  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
like image 427
Holly Avatar asked Apr 02 '13 02:04

Holly


1 Answers

You're trying to redirect to edit_location_path(:id). The symbol :id is not what you want to pass here. You want the location's id or the location itself: redirect_to edit_location_path(@location)

like image 179
Rein Henrichs Avatar answered Oct 07 '22 22:10

Rein Henrichs