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 else render 'edit' //want to render here with an anchor end end
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.