Rails - redirection problem
There is many users available in my project. Each user have different home page. And also i have a default home page. My actual code is here..
requested_url = "/limited/username" #It is constantly changing.
redirect_to(requested_url || :action => "index", :controller => "demo")
So, it redirect the page like this http://localhost:3000/demo/index?%2Flimited=username
. But, actually i need the redirected url like this http://localhost:3000/limited/username
.
If the requested_url
is empty then, it redirects correctly. (http://localhost:30开发者_开发百科00/demo/index
). But, if its not empty then, it redirects wrongly.
Please tell me what is the problem here?.
||
has higher operator precedence than =>
, so your redirect call is interpreted as
redirect_to( (requested_url || :action) => "index", :controller => "demo")
Try this instead:
redirect_to( requested_url || {:action => "index", :controller => "demo"})
Obviously I'm not privy to the exact details of what you're trying to do here, but you might be able to do something like this:
before_filter :redirect_to_requested_url, :if => :requested_url_supplied?
def redirect_to_requested_url
redirect_to ... get requested url somehow ...
end
精彩评论