1

I have a Rails 3 form where I'm using Bootstrap tabs. Each tab renders a different form (but to the same controller).

When I submit the form on tab2, the URL at the top of the page is:

http://localhost:3000/costprojects/1#tab2

In the costprojects controller, I want to go to the next tab when the user submits a form.

I thought this would work:

  def update
    @costproject = Costproject.find(params[:id])
    nextpath =  costproject_path(@costproject) + '#tab2'
    nextpath =  costproject_path(@costproject) + '#tab3' if request.referer.include?("#tab2")
    nextpath =  costproject_path(@costproject) + '#tab4' if request.referer.include?("#tab3")


    respond_to do |format|
      if @costproject.update_attributes(params[:costproject])
        format.html { redirect_to nextpath, notice: 'Capital Project was successfully updated.' } 

But, the request.referer doesn't include the 'tab2'.

How come?

Thanks for the help!

Reddirt
  • 5,913
  • 9
  • 48
  • 126
  • Relying on referer isn't a good idea. Couldn't you provide a hidden field in the form and use that instead? – Marcus May 13 '15 at 19:18

1 Answers1

1

The anchor is only available client side. It's never sent as part of any request header. See Is the anchor part of a URL being sent to a web server?

Community
  • 1
  • 1
Philip Hallstrom
  • 19,673
  • 2
  • 42
  • 46