Forum: Ruby on Rails redirect for render_component

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bala K. (Guest)
on 2008-10-17 10:09
  i am using
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 it possible to redirect
for render_component?.

Patrick S. (Guest)
on 2008-10-17 12:02
(Received via mailing list)
Ditch the component. Whatever you're wanting to display with "myaction",
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
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
put this:

  before_filter :check_for_session

Then, define the "check_for_session" action in your controller and stick
session-checking logic in there. Simply use redirect_to on failures,
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,
will redirect to the login page. Nice and clean.
This topic is locked and can not be replied to.