开发者

Rails do something and redirect?

开发者 https://www.devze.com 2023-03-11 17:57 出处:网络
is there a way to execute code and then redirect inside the routes-file like this: get \'cache/clear\' => Proc.new { Rails.cache.clear && redirect(\'/\') }

is there a way to execute code and then redirect inside the routes-file like this:

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

I just really don't want to create a controller for this particular action.开发者_如何学Python


Yup. 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 && '/'}
0

精彩评论

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