Named route new_session not working

Anyone have any idea why a named route would NOT work? I did rake
routes to make sure it was there and it was but for some reason
new_session doesn’t work.

On 1/16/08, Jimmy P. [email protected] wrote:

Anyone have any idea why a named route would NOT work? I did rake
routes to make sure it was there and it was but for some reason
new_session doesn’t work.

What do you mean, didn’t work? If you are looking for a helper method
called new_session there isn’t one, the named route will generate two
helper methods, in this case new_session_path and new_session_url

But maybe you have some other problem. In any case just “doesn’t
work” doesn’t help us much.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I changed ‘new_session’ in authentication_system.rb to say
‘new_session_path’ and it kind of works…it’s not using my routes
though. Is this a bug?

strange…

On 1/16/08, Jimmy P. [email protected] wrote:

I changed ‘new_session’ in authentication_system.rb to say
‘new_session_path’ and it kind of works…it’s not using my routes
though. Is this a bug?

What do you mean “kind of works”?

What do you mean “it’s not using my routes”?

You gotta tell us more, son!


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I changed “new_session” to “login_path” in the following two instances.

In authenticated_system.rb


    def access_denied
      respond_to do |format|
        format.html do
          store_location
          redirect_to login_path
        end
        format.xml do
          request_http_basic_authentication 'Web Password'
        end
      end
    end

In sessions_controller.rb


  def create
    self.current_user = User.authenticate(params[:login], 
params[:password])
    if logged_in?
      if params[:remember_me] == "1"
        self.current_user.remember_me
        cookies[:auth_token] = { :value => 
self.current_user.remember_token , :expires => 
self.current_user.remember_token_expires_at }
      end
      redirect_back_or_default('/')
      flash[:notice] = "Logged in successfully"
    else
      redirect_to login_path
    end
  end

sorry for the ambiguity. I will work on being more descriptive. :slight_smile:

In the method access_denied in the file authenticated_system.rb from
restful athentication, it generates this:

def access_denied
  respond_to do |format|
    format.html do
      store_location
      redirect_to new_session # <---- NOTICE
    end
    format.xml do
      request_http_basic_authentication 'Web Password'
    end
  end
end

Everytime I hit a ‘login_required’ area of the site I get this error:

undefined local variable or method `new_session’ for
#Admin::CategoriesController:0x18e93dc

I changed the new_session to new_session_url and it works fine but it
redirects it to http://localhost:3000/sessions/new instead of
http://localhost:3000/login.

my routes look like this:

map.with_options :controller => “sessions” do |page|
page.login “/login”, :action => “new”
page.logout ‘/logout’,:action => ‘destroy’
end

rake routes:

new_session GET /session/new {:action=>“new”,
:controller=>“sessions”}

Seems like it should work. Am I missing something?