views:

30

answers:

1

Hello,

this is a silly questions but I don't understand, why rails isn't evaluating my string as expected. Here is my problem:

I want to redirect to an url in the form ~/:controller/index/#_76

  redirect_to :action => "index", :id => '#_76'

But I'm getting the url in the form: ~/:controller/index/%25_76 and so my anchor for linking to a certain place in the website isn't working. Can someone please explain me, why rails makes this rendering? I think this hase something to do with url encoding.

Again thanks for your help, I'm learning every day a little bit more about rails :).

+3  A: 

So your aim is not to "get the "#" symbol into URL". In this you have succeeded: you've been returned a URL with "#" character encoded into it.

What you need is "redirecting to a specific anchor". You don't need to do hacky tricks to bring it into the URL:

redirect_to :action => "index", :anchor => "_76"

Most likely you would want to detach :id from index action, because index is the page specific to the controller as a whole, not for each particular item.

Pavel Shved