redirect for render_component

Hi,   i am using <%=render_component(:controller=>"mycontroller",:action=>"myaction")%> on the view.

in my controller i am checking the conditions whether session is there or not.   if session is there i am rendering myaction view, otherwise i am redirecting to login controller. but it rendering the login page again instead of redirecting.can anybody help me.is it possible to redirect for render_component?.

Thanks Bala

Ditch the component. Whatever you're wanting to display with "myaction", work it in to the view with partials or as the view itself.

A cleaner way of doing this is by using a before filter in "mycontroller". Create an action that will check for the presence of session, and call it as a before filter.

We'll call this action "check_for_session". In your controller, at the top, put this:

  before_filter :check_for_session

Then, define the "check_for_session" action in your controller and stick your session-checking logic in there. Simply use redirect_to on failures, which will send users without sessions to the login page.

Problem solved. When "myaction" is called, the controller will run check_for_session first. If check_for_session doesn't see any session, it will redirect to the login page. Nice and clean.