Rails:立即渲染并退出

man*_*u_v 33 ruby-on-rails

使用omniauth gem,无论提供者如何,我都被迫为成功登录定义单个路由回调:

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
Run Code Online (Sandbox Code Playgroud)

如何防止控制器返回到auth_callback方法并尝试显示相应的视图(不存在)?一旦process_one或process_two方法返回,则应将处理视为完成.

Kel*_*lly 82

为什么不专门打电话给render那些方法呢?

def process_one
 # do something then render view for process_one
 render :process_one and return
end
Run Code Online (Sandbox Code Playgroud)

Rails应该检测到你已经运行它而不是尝试再次渲染.

  • 记住不要使用`&&`而不是`和` (4认同)