redirect_to edit

10,103

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)

Share:
10,103
Holly
Author by

Holly

I am a user who prefers to keep an air of mystery about myself, apparently.

Updated on July 17, 2022

Comments

  • Holly
    Holly almost 2 years

    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