views:

22

answers:

1

Hi Everyone,

I am working on a basic app that has a public facing form (for enquiries) that anyone can fill in and submit. The results are then stored for the company to do what they want with.

I have made sure that if the user is not logged in they can only access the create page, but once they submit the form, as expected, they are taken to the login page because its trying to show them the show page.

My current controller is as follows:

# POST /enquiries
  # POST /enquiries.xml
  def create
    @enquiry = Enquiry.new(params[:enquiry])

    respond_to do |format|
      if @enquiry.save
        format.html { redirect_to(@enquiry, :notice => 'Enquiry was successfully created.') }
        format.xml  { render :xml => @enquiry, :status => :created, :location => @enquiry }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @enquiry.errors, :status => :unprocessable_entity }
      end
    end
  end

I would imagine it's this line that needs to change:

format.html { redirect_to(@enquiry, :notice => 'Enquiry was successfully created.') }

Is it possible to do:

format.html { redirect_to(http://www.google.com) }

Thanks,

Danny

+1  A: 

Yes, you can certainly redirect_to("http://any.url.com/you/want") from your controller or do whatever else you want if create is successful. Redirecting to the show action is just a common pattern.

Is this really what you want to do, though? If you redirect your user to an outside website after submitting the form, you can't give them any feedback at all about what just happened. The user might try to submit the Enquiry again, or worse, they might think something went wrong and just forget about it, lose interest, etc. I'd strongly recommend creating a "Thanks for your enquiry!" page and redirecting anonymous users there.

Dave Pirotte
Hi Dave, I am actually redirecting to a company branded thank you page. I'm sure there are a few better ways of doing what I'm trying to achieve but this is the way it works in my head :D. Thanks for the help!
dannymcc