Rails 3: Rendering actions with named anchors/fragments after failed form submission

The edit view for one of my models contains tabs that utilize anchors in the url to switch between settings such as model/1/edit#tab1 and model/1/edit#tab2. Is there a way to redirect to these anchors after submitting the edit form but failing to save due to errors? My current code is below:

  def update
    @user = Product.new(params[:user])
    if @user.save
      flash[:success] = "Your user has been created"
      redirect_to @user
      render 'edit' //want to render here with an anchor

I would like to store the url containing the anchor before form submit and then re-render the form with the same anchor while rendering error messages. Any ideas?


Best way was to use jquery cookie to save last opened tab and then set default tab using saved cookie.

Need Your Help

Using external js with .php extension in Codeigniter

php javascript codeigniter fatal-error

I am using codeigniter 2 and I have my theme folder consist of js, img, css folders.

Troubleshooting an x64 com interop marshaling issue

.net c++ 64bit com-interop

I have a C++ COM Server which I have recently recompiled to 64 bit. This COM server has a method that contains a struct parameter which contains some ints and a BSTR and another structure. Now, I...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.