Topic: jumping to a named link on page with redirect_to

I have a checkbox on my /list page that shows a table of exercices.  Each row has a 'publish' checkbox the user can check on, or off.

.
.
.
.
.<%= check_box("exercise", "publish", "onclick" => "document.location.href='/library/exercise/toggle_check/#{@exercise.id}'" + " ", :params => { :category => @category.id, :subcategory => @subcategory.id }) %>
.
def toggle_check
    @exercise = Exercise.find(@params['id'])
    @exercise.publish = !(@exercise.publish?)
    @findcategory = Category.find(@params["category"]) if @params["category"]
    @findsubcategory = Subcategory.find(@params["subcategory"]) if @params["subcategory"]
 
    if @exercise.save
      redirect_to(:action => "list")
    else
      render_text "Couldn't update item"
    end
end

.


which, when the onclick happens, a function in the controller is run to toggle the data in the database.  This works fine.
What I'd like to do is have the redirect_to(:action => "list") to jump to a named link <a name='12'> on the list page so the user doesn't have to scroll back to their spot again.

I want the user to get here http://www.mysite.com/library/exercise/list#12

Is this possible?
Al

Last edited by alanpieroway (2006-11-22 23:51:37)

Re: jumping to a named link on page with redirect_to

redirect_to :controller => 'posts', :action => 'index', :anchor => 'post_12'

This will go to http://your.host/posts/#post_12.

Another tip: don't start identifiers with numbers, that's not valid. Name your anchor post12 or post_12 or something other than just its ID number from the database.

vinnie - rails forum admin

Re: jumping to a named link on page with redirect_to

thanks. works nicely. and i did what you said, and prefaced the link name with some text. ex: ex_12
regards,
al