Mage
(Mage)
1
Hello,
I would like to exit an action, however, I cannot use return because it should be called from another method:
def click
requires_valid_login
other_things
end
protected
def requires_valid_login
if !@user
flash[:error] = 'you must be logged for view this page'
redirect_to :back
end
end
Is there any elegant way to exit from action :click and don't process "other things"?
I could use:
requires_valid_login or return
However I don't like this.
Mage
Sixty4Bit
(Sixty4Bit)
2
Hope this helps...
def click
return unless valid_login
other_things
end
def valid_login
if !@user
flash[:error] = 'you must be logged for view this page'
redirect_to :back
false
end
true
end
Sixty4Bit
(Sixty4Bit)
3
Uhhhh to keep the syntax ruby-like you should rename valid_login to valid_login?
bitsweat
(Jeremy Daer)
4
Use a before_filter and return false, aborting the action.
jeremy
Mage
(Mage)
5
Jeremy Kemper wrote:
Use a before_filter and return false, aborting the action.
Thank you, I am already using before filter which does the authentication, however I don't want to abort every actions, only some of them.
Is it possible to abort the action inside from a method called by the action itself?
Mage
Mage
(Mage)
6
Carl Fyffe wrote:
Hope this helps...
def click
return unless valid_login
other_things
end
That's what I am trying to avoid, the explicit return from the action itself.
Mage