【发布时间】:2015-02-25 12:06:37
【问题描述】:
我想在动作之外设置“respond_to”动作的一部分。
这是一个应该如何工作的示例:
def index
...
end
def show
...
end
response_for :index, :show do
format.html do
if empty_records?
redirect_to root_path
end
end
format.json do
...
end
end
之前我为此使用了response_for gem,但它不再受支持。您可以建议哪些解决方案?我使用 Rails 4.2。
【问题讨论】:
-
1.大部分遗留代码都是这样写的 2. DRY 原则
标签: ruby-on-rails ruby-on-rails-4 actionpack