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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With