views:

43

answers:

2

I'd like my application to display different data on the frontpage depending on whether the user has been logged in or not.

def index

  if current_user
    # render another controllers action
  else
    # render another controllers action
  end

end

I can achieve this by using render_component. However it has been obsolete for some time. Although I can still use it as a plugin, I'm interested if anyone has a better approach. Just take in mind that rendering another controller's view directly is not an option.

Thanks.

A: 

If it is a relatively small subsection of data, I'd probably do that in a view helper.

Mike Buckbee
Thanks for the suggestion, but it doesn't apply very well for my application.
vise
It might be useful to explain more of what your exact situation is: it seems like you're looking for something in between doing a redirect_to different actions and a view helper.
Mike Buckbee
+1  A: 

Just use your index method as a public proxy to the specific view you want to render.

def index
  if user?
    logged_in
  else
    logged_out
  end
end

private

def logged_in
  # stuff
  render :action => "logged_in"
end

def logged_out
  # stuff
  render :action => "logged_out"
end    
Chris Heald