Bapi_agent
Bapi_agent

Reputation: 11

How to solve Template is missing error using Rails 3?

I am getting the below error while my page is failed to lagged in.If i am typing wrong password/email and clicked on submit then the bellow error is coming.

Error:

Template is missing

Missing template sessions/member, application/member with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Site/library_management1/app/views" * "C:/Ruby193/lib/ruby/gems/1.9.1/gems/devise-3.4.1/app/views"

My codes are as follows.

views/homes/member.html.erb

<% if current_user %>
<div class="totaldiv">
  <div class="navdiv"><span>STUDENT INFORMATION</span><span>Logged in as <%= current_user.email %></span></div>
  <div class="wrapper">
  <div id="leftsidebtn">
 <ul>
  <li><a href="/homes/issuebooks">Book issue</a></li>
   <li><a href="/homes/availablebooks">Books Available</a></li>
<li><a href="/sessions/removeuser">Log Out</a></li>
 </ul>  
</div>
  </div>
  <div class="restdiv" id="ex3" >
    <center>


</center>
  </div>
</div>
<% else %>
<div class="totaldiv">
  <div class="navdiv"><span>STUDENT INFORMATION</span></div>
  <div class="wrapper">
  <div id="leftsidebtn">
 <ul>
<li><a href="/homes/registration">Registration</a></li>
<li><a href="/homes/index">Back</a></li>
 </ul>  
</div>
  </div>
  <div class="restdiv" id="ex3" >
    <center>

  <div class="studentlogin">
    <h1>Login Here</h1>
<section class="studentloginloginform cf">
      <%= form_for :users,:url => {:action => 'loginuser',:controller => 'sessions'} do |f| %>
      <% if @users.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@users.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @users.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
      <ul>
        <li>
          <label for="usermail">Email</label>
          <%= f.email_field :email,placeholder:"[email protected]" %>
        </li>
        <li>
          <label for="password">Password</label>
           <%= f.password_field :password,placeholder:"password" %>
          </li>
        <li>
          <%= f.submit 'LogIn',:class => 'studentsubmit' %>
        </li>
        <li class="reg_member">
          Not a member ? <%= link_to 'Register Here',homes_registration_path %>
        </li>
      </ul>
      <% end %>
  </section>
</div>
</center>
  </div>
</div>
 <% end %>

controller/sessions_controller.rb

class SessionsController < ApplicationController
    def loginuser
        @users=User.authenticate(params[:users][:email], params[:users][:password])
        if @users
            session[:user_id][email protected]
            cookies.signed[:user_id][email protected]
            flash[:notice]="login successfull"
            flash[:color]="valid"
            redirect_to :action => 'member',:controller => 'homes'
        else
            flash[:notice]="could not Logged in"
            flash[:color]="invalid"
            render 'member', :controller => 'homes'
        end
    end
    def removeuser
        session[:user_id] = nil
        cookies.delete :user_id
        flash[:notice]="user logged out successfully"
        flash[:color]="valid"
        redirect_to :action => 'member', :controller => 'homes'
    end
end

model/user.rb

class User < ActiveRecord::Base
  attr_accessible :address, :email, :first_name, :last_name, :password, :password_hash, :password_salt, :tel_no ,:password_confirmation
  attr_accessor :password
  before_save :encrypt_password
 EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\z/i
 validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
 validates :first_name, :presence => true, :length => {:in => 3..10}
 validates :last_name , :presence => true , :length => {:in => 3..10}
 validates :tel_no , :presence => true , :length => {:in => 1..10}
 validates :password, :confirmation => true
 validates_length_of :password, :in => 6..20, :on => :create
 def self.authenticate(email, password)
    user = find_by_email(email)
    if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
      user
    else
      nil
    end
  end

  def encrypt_password
    if password.present?
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
    end
  end
  has_many :issue
  has_many :book
end

Please check the codes and try to resolve this error.

Upvotes: 0

Views: 76

Answers (2)

Sumit Mahamuni
Sumit Mahamuni

Reputation: 302

In your controller change line render 'member', :controller => 'homes' with following.

render 'homes/member'

Upvotes: 1

user3118220
user3118220

Reputation: 1468

You template is missing on "sessions/member" path

I guess, create a template in following path to resolve it

 views/sessions/member.html.erb

Upvotes: 0

Related Questions