# Named route new\_session not working

**URL:** <https://www.ruby-forum.com/t/named-route-new-session-not-working/126288>\
**Category:** Rails\
**Created:** [January 17, 2008, 12:09am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288 "2008-01-17T00:09:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 17, 2008, 12:09am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/1 "2008-01-17T00:09:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 17, 2008, 12:25am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/2 "2008-01-17T00:25:50Z")

</div>

On 1/16/08, Jimmy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 17, 2008, 12:24am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/3 "2008-01-17T00:24:47Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 17, 2008, 12:31am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/4 "2008-01-17T00:31:05Z")

</div>

On 1/16/08, Jimmy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 30, 2008, 8:57pm UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/5 "2008-01-30T20:57:46Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [January 17, 2008, 12:36am UTC](https://www.ruby-forum.com/t/named-route-new-session-not-working/126288/6 "2008-01-17T00:36:17Z")

</div>

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

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](http://localhost:3000/sessions/new) instead of  
[http://localhost:3000/login](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?
