I understand that render :action
only renders an action's view. But I was wondering.. Is there no easy way to execute the code in that action before its view is rendered?
如果你试图在两个不同的控制器中重用逻辑,为什么不把它的逻辑从当前的控制器中拉出来像一个辅助方法或类更可重用?
Yes, there is.
class TestolaController < ApplicationController
def foo
redirect_to :action => "bar"
end
def bar
puts "in bar"
end
end
def foo
bar
end
def bar
puts "in bar"
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.