title: User sessions and logins
body: <p>I am trying to implement signup &amp; login features on ROR. on Index page i have created 2 links saying 'new user' and 'login' and in userscontroller i have signup &amp; login methods(updated routes accordingly).  </p>
  
  <p>prob: upon clicking new user or login i am getting an error saying  </p>
  
  <p>"The action 'show' could not be found for UsersController"</p>
  
  <p>routes.rb:</p>
  
  <pre><code>Rails.application.routes.draw do
  
  resources :users
  
  get 'users/register', :to=&gt;'users#register'
  get 'users/signup', :to=&gt;'users#signup'
  post 'users/signup', :to=&gt;'users#signup'
  post 'users/login', :to=&gt;'users#login'
  get 'users/login', :to=&gt;'users#login'
  post "users/change_password" =&gt; "users#change_password"
  get "users/change_password" =&gt; "users#change_password"
  </code></pre>
  
  <p>index.html.erb</p>
  
  <pre><code>&lt;%= link_to "New User", users_register_path %&gt;&lt;br&gt;
  &lt;%= link_to "Login", users_login_path %&gt;&lt;br&gt;
  &lt;%= link_to "Change Password", users_change_password_path %&gt;&lt;br&gt;
  </code></pre>
  
  <p>userscontroller:</p>
  
  <pre><code>def index
    @user_details = User.all
  end
  
  def register
    puts "**********************"
    puts params
    @new_user = User.new
  end
  
  def signup
    @new_user = User.new(user_register)
    if @new_user.save
    session[:user] = User.authenticate(@user.name,@user.password)
    redirect_to :action=&gt;"welcome"
   else
     redirect_to :action=&gt;"login"
   end
  end
  
  def login
    puts params
    if request.post?
    session[:user] = User.authenticate(params[:user][:name],   params[:user][:password])
     redirect_to :action=&gt;"welcome"
    else
    #  redirect_to :action=&gt;"signup"
   end
  end
  
  
  
   def change_password
  
     puts "**********************"
     puts params
     puts "**********************"
  
    if request.post?
    @pass_change = User.new_password(params[:user][:name], params[:user][:password], params[:user][:new_password])
   end
  end
  
  def welcome
   end
  
  
   def user_register
      params.require(:user).permit(:name,:email,:password,:password_confirmation)
   end
  
   end
  </code></pre>
  
  <p>usermodel.rb:</p>
  
  <pre><code>require 'digest/sha1'
  
  class User &lt; ActiveRecord::Base
  
  
   attr_accessor :password, :password_confirmation
  
   def password=(pass)
      @password = pass
  
     self.salt = User.random_met(10)
     self.hashedpassword = User.encrypt(@password, self.salt)
   end
  
    def self.encrypt(pass,salt)
       Digest::SHA1.hexdigest(pass+salt)
    end
  
    def self.authenticate(login, pass)
      user_auth = User.find(:first, :conditions=&gt;["login = ?", login])
      return nil if user_auth.nil?
      return user_auth if     User.encrypt(pass,user_auth.salt)==user_auth.hashedpassword
    end
  
  
     def self.new_password(name,old,new)
        user = where(:name=&gt;name)
        #puts user.email
  
       # how to call setter(password) method from here. because   My idea is
       #if User.encrypt(old, user.salt)==user.hashedpassword
       # run def password=(pass), thereby storing new password.
      end
  
    def self.random_met(len)
       char = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
       salted = ""
        1.upto(len) { |i| salted &lt;&lt; char[rand(char.size-1)] }
      return salted
     end
  
    end
  </code></pre>