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
follows:
DEMO03::Application.routes.draw do
root :to => "sessions#new"
resources :sessions
resources :users do
resources :projects do
resources :locations
end
end
get "logout" => "sessions#destroy", :as =>
"logout"
get "login" => "sessions#new", :as =>
"login"
get "signup" => "users#new", :as =>
"signup"
get "secret" => "secret#index"
end
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] = user.id
redirect_to user_projects, :notice => "#{current_user.email}
logged in."
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
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 => "#{current_user.email}
logged in - from Controller index."
end
and got the following:
undefined local variable or method `user_projects'' for
#<SessionsController:0x00000103d61380>
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
work.
Not sure how to diagnose further. Any assistance would be appreciated.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.