开发者

How to get the "#" symbol in the :id into the redirect_to method in Rails

this is a silly questions but I don't 开发者_C百科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 :).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜