2015-04-06 48 views
0

我尝试通过发送链接发送电子邮件并打开该电子邮件链接来重置密码时出现以下错误。未定义的方法`Password_field'使用Rail3的错误

错误:

NoMethodError in Admins#editpass 

Showing C:/Site/swargadwar_admin/app/views/admins/editpass.html.erb where line #16 raised: 

undefined method `Password_field' for #<ActionView::Helpers::FormBuilder:0x21c0108> 
Extracted source (around line #16): 

13:  <% end %> 
14:  <p> 
15:   <label for "new_pass">New Password :</label> 
16:   <%= f.Password_field :password,placeholder:"Enter your new password" %> 
17:  </p> 
18:  <p> 
19:   <label for "new_pass">Confirm New Password :</label> 
Rails.root: C:/Site/swargadwar_admin 

Application Trace | Framework Trace | Full Trace 
app/views/admins/editpass.html.erb:16:in `block in _app_views_admins_editpass_html_erb___904659562_17338176' 
app/views/admins/editpass.html.erb:2:in `_app_views_admins_editpass_html_erb___904659562_17338176' 

请检查下面我的代码,让我知道我做了错误以及尽量帮我解决这个问题。

的意见/管理员/ editpass.html.erb

<center> 
    <%= form_for :admin,:url => {:action => "setpass",:id => params[:id] } do |f| %> 
    <% if @admin.errors.any? %> 
     <div id="error_explanation"> 
     <h2><%= pluralize(@admin.errors.count, "error") %> prohibited this post from being saved:</h2> 

     <ul> 
     <% @admin.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
     </div> 
    <% end %> 
    <p> 
     <label for "new_pass">New Password :</label> 
     <%= f.Password_field :password,placeholder:"Enter your new password" %> 
    </p> 
    <p> 
     <label for "new_pass">Confirm New Password :</label> 
     <%= f.Password_field :password_confirmation,placeholder:"confirm your new password" %> 
    </p> 
    <p> 
     <%= f.submit "Submit" %> 
    </p> 
    <% end %> 
</center> 

控制器/ admins_controller.rb

class AdminsController < ApplicationController 
    def create_registration 
     @admin=Admin.new(params[:admin]) 
     if @admin.save 
      flash[:notice]="User has created successfully" 
      flash[:color]="valid" 
      redirect_to :action => "index" , :controller => 'homes' 
     else 
      flash[:alert]="User could not created" 
      flash[:color]="invalid" 
      render 'homes/index' 
     end 
    end 
    def forget 
     @admin=Admin.new 
    end 
    def resetpass 
     @admin=Admin.find_by_email(params[:admin][:email]) 
     if @admin.email==params[:admin][:email] 
      UserMailer.registration_confirmation(@admin).deliver 
      flash[:notice]="Check your email to reset the password" 
      flash[:color]="valid" 
      redirect_to :action => "index" , :controller => 'homes' 
     else 
      flash[:alert]="Invalid email id" 
      flash[:color]="invalid" 
      render 'homes/index' 
     end 
    end 
    def editpass 
     @admin=Admin.new 
    end 
    def setpass 
     @admin=Admin.find(params[:id]) 
     if @admin.update_attributes(params[:admin]) 
      flash[:notice]="Your password has updated successfully" 
      flash[:color]="valid" 
      redirect_to :action => "index" , :controller => 'homes' 
     else 
      flash[:alert]="Your password could not updated" 
      flash[:color]="invalid" 
      render 'homes/index' 
     end 
    end 
end 

模型/ admin.rb

class Admin < ActiveRecord::Base 
    attr_accessible :email, :password_hash, :password_salt, :picture, :user_name,:password_confirmation,:password, :remember_me 
    attr_accessor :password 
    attr_accessor :remember_token 
    before_save :encrypt_password 
    mount_uploader :picture, PictureUploader 
    EMAIL_REGEX = /\A[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\z/i 
    validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX 
    validates :user_name, :presence => true, :length => {:in => 3..10} 
    validates :password, :confirmation => true 
validates_length_of :password, :in => 6..20, :on => :create 
has_secure_password 
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 
    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 Admin.digest(string) 
    cost = 10 
    BCrypt::Password.create(string, cost: cost) 
    end 

    # Returns a random token. 
    def Admin.new_token 
    SecureRandom.urlsafe_base64 
    end 

    # Remembers a user in the database for use in persistent sessions. 
    def remember 
    self.remember_token = Admin.new_token 
    update_attribute(:remember_digest, Admin.digest(remember_token)) 
    end 
    def forget 
    update_attribute(:remember_digest, nil) 
    end 
end 

请帮助我。

回答

0

你只是有一个错字:方法被命名为password_field,而不是Password_field。只需更改app/views/admins/editpass.html.erb中的两个方法调用即可完成。

相关问题