Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

Rails : render and exit immediately

Using the omniauth gem, I am forced to define a single route callback for succesful logins, regardless of the provider :

def auth_callback 

        auth_data = request.env['omniauth.auth']

        if auth_data.has_key('something')
            process_one(auth_data)
        else
            process_two(auth_data)
        end

        # No view is available here

end


def process_one
    # do something then render view for process_one
    return
end

def process_two
    # do something then render view for process_two
    return
end

How can I prevent the controller from returning to the auth_callback method and try to display the corresponding view (which does not exist) ? Treatment should be considered as complete once the process_one or process_two methods have returned.

question from:https://stackoverflow.com/questions/5539106/rails-render-and-exit-immediately

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why not specifically call render in those methods?

def process_one
 # do something then render view for process_one
 render :process_one and return
end

Rails should detect that you've already run it and not try to render again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...