return from an action

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

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

Uhhhh to keep the syntax ruby-like you should rename valid_login to valid_login?

Use a before_filter and return false, aborting the action.

jeremy

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

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