2

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?

4

3 回答 3

3

如果您尝试在两个不同的控制器中重用逻辑,为什么不将该逻辑从其当前控制器中拉出到更可重用的东西中,例如辅助方法或类?

于 2012-10-12T12:29:40.840 回答
0

就在这里。

class TestolaController < ApplicationController
  def foo
    redirect_to :action => "bar"
  end

  def bar
    puts "in bar"
  end
end
于 2012-10-12T11:11:15.557 回答
0
  def foo
    bar
  end

  def bar
    puts "in bar"
  end
于 2012-10-12T11:41:00.820 回答