Nest Resources including sessions in Rails 3 Issue

Hello all -

I have looked through the newsgroups and been unable to find my
specific issue, or a resolution, and I am stuck, so I am posting to
ask for help, or a link to something I may have missed.

I have an application that allows users to log in, create a project
and associate locations with their projects.

I am using nested resources to map users to projects to resources as

DEMO03::Application.routes.draw do
root :to => “sessions#new”

resources :sessions

resources :users do
  resources :projects do
    resources :locations

get “logout” => “sessions#destroy”, :as => “logout”
get “login” => “sessions#new”, :as => “login”
get “signup” => “users#new”, :as => “signup”
get “secret” => “secret#index”

If I run rake routes, I get routes that allow me to get to
user_project_locations and user_projects (among others). However, when
I attempt to redirect_to user_project_locations from my sessions
controller after creating a new session as follows:

def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] =
redirect_to user_projects, :notice => “#{}
logged in.”
else = “Invalid email or password”
render “new”

I received an error indicating there was no index method in my
sessions controller. I tried adding the following:

def index
redirect_to user_projects, :notice => “#{}
logged in - from Controller index.”

and got the following:

undefined local variable or method `user_projects’ for

It looks like for some reason I cannot use named routes that rake
output suggests should be available.

I also tried nesting user, project and location inside sessions (which
intuitively seemed wrong, but tried it anyway) - which also didn’t

Not sure how to diagnose further. Any assistance would be appreciated.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs