Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 916
manu_v Avatar asked Apr 04 '11 13:04

manu_v


People also ask

Does Redirect_to return?

redirect_to is not return Keep in mind that redirect_to does not cause the action to stop executing. It is not like calling return in a Ruby method.

How can you tell Rails to render without a layout?

By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.

What is render partial in rails?

Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

What does render do in Rails?

Rendering is the ultimate goal of your Ruby on Rails application. You render a view, usually . html. erb files, which contain a mix of HMTL & Ruby code.


1 Answers

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.

like image 88
Kelly Avatar answered Sep 29 '22 09:09

Kelly