在Ruby on Rails中发送devise的密码 [英] Send Password for devise in Ruby on Rails

查看:315
本文介绍了在Ruby on Rails中发送devise的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个Ruby on Rails的应用程序。

Hi i have an app on Ruby on Rails..

这是使用GEM的。 GEMFILE

This is the GEMs im using. GEMFILE

gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

#gem 'pg'
gem 'mysql2'

gem 'json'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :test, :development do
  gem "rspec-rails"
  gem "shoulda"
  #gem "factory_girl_rails"
end

gem 'simple_form'
gem "nested_form"
gem 'wicked'
gem "paperclip", "~> 3.0"
gem 'ruby-units'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

#gem 'therubyracer'
#gem 'less-rails'
gem 'devise'
gem 'globalize3'
gem 'cancan'

然后在模型中,在user.rb中我得到这个

Ok then in the models , in user.rb i got this

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  has_and_belongs_to_many :roles
  has_one :player
  has_many :payment_notifications


  attr_accessible :email, :password, :password_confirmation, :remember_me, :user_type, :purchased_at


  validates :email,
            :presence => true

  after_create :is_a_player?

  def role?(role)
    return !!self.roles.find_by_name(role.to_s)
  end

  def is_a_player?
    if user_type == 'player' || user_type == 'coach'
      self.create_player(:active => false)
      self.roles << Role.find_by_name(:player)
    elsif user_type == 'elite'
      self.roles << Role.find_by_name(:elite)
    end
  end

  #private

    def paypal_url(return_url)

    values = {
      :business      => 'mm@hotmail.com',
      :cmd           => '_cart',
      :upload        => 1,
      :return        => return_url,
      #:invoice       => 13, #id,
      #:notify_url    => notify_url,
      :amount_1      => '100',
      :item_name_1   => 'Suscripcion a Myr',
      :item_number_1 => '1',
      :quantity_1    => '1'
    }

    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
  end

    def purchase_defeated?

      t = Time.now - purchased_at

      mm, ss = t.divmod(60)
      hh, mm = mm.divmod(60)
      dd, hh = hh.divmod(24)

      dd > 180 ? true : false

    end

end

我正在寻找写入发送密码的文档(如果忘记了),但是我发现这个设计,允许用户更改密码

I was looking for documentation for writing the send password (if forgot) but i found this Devise, allowing users to change passwords

当我在登录页面的视图中插入此链接

When i insert this link on the View where the login is

<%= link_to 'Change Password', edit_user_registration_path %>

我刚刚重定向到同一页面..我该怎么做这个视图?

Im just redirected to the same page.. how can i make this view?

如何定义此视图的路径?不能写这个:(

How can i define the path to this view.. cant write this :(

更新:

在控制器/ admin / user_controller中,我发现这个

In controllers/admin/user_controller i found this

def update
    @user = User.find(params[:id])
    params[:user].delete(:password) if params[:user][:password].blank?
    params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
    if @user.update_attributes(params[:user])
      flash[:notice] = "Successfully updated User."
      redirect_to users_path
    else
      render :action => 'edit'
    end
  end

还有一个视图也有

<h1><%= t('generales.edit_user') %></h1>

<%= render 'form' %>

更改我的问题..我可以将其从管理员移动到公开吗?

Change my question.. how can i move this from admin to public?

复制控制器的那一部分,并在视图中插入链接。

do i just have to copy that part of controller .. and insert the link in the view?

推荐答案

edit_user_registration_path 不是忘记密码路径

edit_user_registration_path is not for forgot password path

请参阅 Devise共享链接

您可以将此链接包含到您的登录表单

You could include this link into your login form

<%= link_to "Forgot your password?", new_password_path(resource_name) %>

这篇关于在Ruby on Rails中发送devise的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆