Reputation: 1846
In Rails 3 you can set up your root path to redirect elsewhere right from config/routes.rb:
root :to => redirect("/dashboard")
This works, except that it wipes out any flash params passed to root. How can you pass them along through the redirect?
Update: James Chen's solution, i.e. rewriting the route declaration as root :to => redirect { |p, req| req.flash.keep; "/dashboard" }
, works for me. But there are two things I don't understand about it:
p
stand for, params?I tried rewriting the block with do
/end
and linebreaks:
root :to => redirect do |p, req|
req.flash.keep
"/dashboard"
end
But this fails with "ArgumentError: redirection argument not supported". Why is this?
Upvotes: 3
Views: 3480
Reputation: 341
why wouldnt you just do something like
root :to => 'dashboard#index'
assuming that '/dashboard' leads to the dashboard controller index action.
Update
I mean if you reallllly wanted to you could add to the html.erb page that is displayed at '/dashboard'
and do something like this
<% if request.referer.scan('yoursitename').size == 0 %>
<%= create your own notice here %>
<% end %>
Edit again... sigh..
Forgot, you could just root :to => 'whateveryouroriginal#rootareawas'
then just do:
redirect_to '/dashboard'
in your whateveryouroriginal controller rootareawas action
This is really dirty but its 2am and i have to drive to Georgia from Illinois.
Hope this helps
Upvotes: 3
Reputation: 10874
Use flash.keep
.
Write a proc for the redirect in your routes file:
root :to => redirect { |p, req| req.flash.keep; "/dashboard" }
So flash params from normal redirect to root url will be passed:
redirect_to root_url, :notice => "test flash notice"
Upvotes: 12