error in login form

Hi

I create a simple application logintest

first i create a controller using this command

script/generate controller home index

and define this controller as root.

then i create a model like this script/generate model user user_name:string password:string

create the controller the like this script/generate controller user index pri

index.html.erb

<% if flash[:notice] %>

<%= flash[:notice] %>
<% end %>

<%= form_tag :action=>‘authenticate’ %>
User name:
<%= text_field(“userform”, “user_name”,:size=>“20” ) %>
Password:
<%= password_field(“userform”, “password”,:size=>“20” )
%>

pri.html.erb

hello <%=session[:user_id]%>.

<%= link_to “logout”,:controller => “user”, :action => “logout” %>

user_controller.rb

class UserController < ApplicationController
def authenticate
#User.new(params[:userform]) will create a new object of User, retrieve values from the form and store it variable @user.
@user = User.new(params[:userform])
#find records with username,password
valid_user = User.find(:first,:conditions => [“user_name = ? and password = ?”,@user.user_name, @user.password])

    #if statement checks whether valid_user exists or not
    if valid_user
    #creates a session with username
        session[:user_id]=valid_user.user_name
    #redirects the user to our private page.
        redirect_to :action => 'pri'
    else
        flash[:notice] = "Invalid User/Password"
        redirect_to :action=> 'index'
    end

end

def index
end

def pri
if !session[:user_id]
redirect_to :action=> ‘index’
end
end

def logout
if session[:user_id]
reset_session
redirect_to :action=> ‘index’
end
end
end

when i call this page using this code <%= link_to “login”, user_path %> from my home/index.html.erb it shows the error

NameError in Home#index

Showing app/views/home/index.html.erb where line #2 raised:

undefined local variable or method `user_path' for #<ActionView::Base:0xb66b60f0>

How to solve this?

Thanks in advance

Regards,

Suji A.


``