Do Rails do something and redirect?

There is a way to execute the code and then redirect inside the routes file as follows:

get 'cache/clear' => Proc.new { Rails.cache.clear && redirect('/') }

I just don't want to create a controller for this particular action.

+3
source share
1 answer

Yeah. See here: http://www.railsdispatch.com/posts/rails-routing

match "/foo", :to => proc {|env| [200, {}, ["Hello world"]] }

or more specifically for your case

match "cache/clear", :to => redirect {Rails.cache.clear && '/'}
+1
source

All Articles