1

Basically what I'm trying to do (it probably has no sense) is using actions without view, no render and so on. The idea is that I'm gonna have a lot of actions which are gonna perform different stuff and return OK or KO, when OK I'll redirect to my OK page and when KO I'll redirect to KO page.

Of course I can handle these redirects within the action but since all my actions will share the redirects I'd like to handle that in an around filter inside some ApplicationController which inherits from ActionController, something like

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

But of course I'm getting double render error or missing template error because I can't keep an action without any view. So the question... is there any way to do that? Handle all the redirects in just one place?

4

1 に答える 1

0

とても簡単でした... ApplicationController に次のような新しい関数を作成するだけでした

def after_finish
    if result
        redirect_to ok_page
    else
        redirect_to ko_page
    end
end

レンダリングやリダイレクトを行わずに各アクションでその関数を呼び出します。簡単です。

于 2012-09-12T09:56:13.513 に答える