Redirect after login

Hi,

I'm new to Ruby/RoR so please bare with me!

I'm trying to adapt a ruby setup where someone logs in to a bonjour
service via a web browser. I have the login screen which asks for host
and password. There is only one user per host and i can log in fine.
It's suppose to redirect me to /list in my browser but
doesn't. Once i've entered the correct login credentials and manually
add /list to the address i can see what i want. So the login seems to
work, it just doesn't redirect me. I need it to redirect me though when
the login is successful.

The part i believe i need to edit;

class JobController < ApplicationController
  before_filter :verify_login, :except => [:index, :login_to_engine]
  before_filter :engine, :except => [:index, :login_to_engine]

  def verify_login
    unless session[:engine_host]
      redirect_to :controller => 'job', :action => 'index'
      return false
    end

    return true
  end

which is in my controllers directory.

Any help appreciated!

Hi

  def verify_login
    unless session[:engine_host]
      redirect_to :controller => 'job', :action => 'index'
      return false
    end

    return true
  end

     Can u change it to

   def verify_login
     unless session[:engine_host]
       redirect_to :controller => 'job', :action => 'index' and return
false
     end
      return true
   end

Sijo

redirect_to :controller => 'job', :action => 'index' and return false

Hi
   If it is needed by more controllers not only jobs controller you can
move it to application.rb and the filter too..Does it call the filter?

Sijo

Hi
    Please do like
Application controller as it is

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection
for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password

  def verify_login
    unless session[:engine_host]
      logger.debug "no engine host in session, redirecting to job/index"
      redirect_to :controller => 'job', :action => 'index'
      return false
    end
    return true
  end
end

In jobs controller you dont need verify_login So

class JobController < ApplicationController
  before_filter :verify_login, :except => [:index, :login_to_engine]
  before_filter :engine, :except => [:index, :login_to_engine]

end

Sijo

Sijo Kg wrote:

Hi
    Please do like
Application controller as it is

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection
for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password

  def verify_login
    unless session[:engine_host]
      logger.debug "no engine host in session, redirecting to job/index"
      redirect_to :controller => 'job', :action => 'index'
      return false
    end
    return true
  end
end

In jobs controller you dont need verify_login So

class JobController < ApplicationController
  before_filter :verify_login, :except => [:index, :login_to_engine]
  before_filter :engine, :except => [:index, :login_to_engine]

end

Sijo

Sijo,

This STILL doesn't work. Could it be because nowhere in here have i told
it where to redirect to? Can i add an IF statement to the def
verify_login in the application controller?

Thanks for your help so far!

Dan

Hi
   And what is wrong now? Did you ensure if session[:engine_host] is not
set it enters to unless session[:engine_host].....end
   For example write some puts inside unless
session[:engine_host]......end

And check if that happens according to what you specify

Sijo

Hi

There you have to use

   and return

      as I said earlier..
  Please read 2.2.13 Avoiding Double Render Errors from
http://guides.rubyonrails.org/layouts_and_rendering.html

Sijo

Dan Sinclair wrote:

Sijo Kg wrote:

Hi

There you have to use

   and return

      as I said earlier..
  Please read 2.2.13 Avoiding Double Render Errors from
http://guides.rubyonrails.org/layouts_and_rendering.html

Sijo

It still doesn't work!!

It says that it's redirected in Terminal, but it doesn't redirect my
HTML (web browser)...

I've done all that you have said, but nothing is working :frowning:

Dan

Ok, so i think i've narrowed it down to where i think i need to
change/add code...

In my job_controller.rb file, i have:

def list
end

so could this be the problem, as i haven't told it to "point" anywhere?
If so, what would i add to define this as a different webpage?

Dan