Ruby on rails 3.2 Rails3:不带渲染和重定向的操作

Ruby on rails 3.2 Rails3:不带渲染和重定向的操作,ruby-on-rails-3.2,Ruby On Rails 3.2,基本上,我试图做的(可能没有意义)是使用没有视图的动作,没有渲染等等。我的想法是,我将有很多动作,它们将执行不同的东西,并返回OK或KO,当OK时,我将重定向到我的OK页面,当KO时,我将重定向到KO页面 当然,我可以在操作中处理这些重定向,但由于我的所有操作都将共享重定向,因此我希望在从ActionController继承的某个ApplicationController中的一个around筛选器中处理这些重定向,例如 around_filter :my_filter def around_fi

基本上,我试图做的(可能没有意义)是使用没有视图的动作,没有渲染等等。我的想法是,我将有很多动作,它们将执行不同的东西,并返回OK或KO,当OK时,我将重定向到我的OK页面,当KO时,我将重定向到KO页面

当然,我可以在操作中处理这些重定向,但由于我的所有操作都将共享重定向,因此我希望在从ActionController继承的某个ApplicationController中的一个around筛选器中处理这些重定向,例如

around_filter :my_filter
def around_filter
    check same stuff for all the actions
    return = yield
    if return == ok
        redirect_to ok_page
    else
       redirect to ko_page
      end
end
def after_finish
    if result
        redirect_to ok_page
    else
        redirect_to ko_page
    end
end

但我当然会遇到双重渲染错误或缺少模板错误,因为我无法在没有任何视图的情况下保留操作。所以问题是。。。有办法吗?在一个地方处理所有重定向?

好的,很简单。。。我只需要在ApplicationController上创建一个新函数,比如

around_filter :my_filter
def around_filter
    check same stuff for all the actions
    return = yield
    if return == ok
        redirect_to ok_page
    else
       redirect to ko_page
      end
end
def after_finish
    if result
        redirect_to ok_page
    else
        redirect_to ko_page
    end
end
并在每个动作上调用该函数,之前不需要渲染或重定向,轻松