我需要解密由devise生成的密码.
例如,我的密码是test123test.设计生成此密码:
$2a$10$vGeVVu.E0XGjlNEa0xMCK.R0SEH0aFuyJpefrq01Axz6WSbHApPEu
Run Code Online (Sandbox Code Playgroud)
我需要解密密码并发送test123test.
我正在尝试使用设计恢复用户的密码,但它会生成以下错误
undefined method `reset_password_sent_at=' for #<User:0x007fb78cfafb68>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我,因为我是Ruby on Rails的新手?
使用Devise恢复密码和向用户发送电子邮件的最佳方法是什么?非常感谢你...
我用的是装饰(2.2.3)
User.rb
require 'digest/md5'
class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
belongs_to :shop
before_create :compute_email_md5
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable,
:rememberable,
:trackable,
:validatable,
:token_authenticatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email,
:email_md5,
:password,
:password_confirmation,
:shop_id,
:role,
:terms,
:name,
:notify_on_order_received
validates :terms, :acceptance => true, :on => …Run Code Online (Sandbox Code Playgroud) 我需要从另一个控制器调用方法.什么是最好的方法?例如:
catalogues_controller.rb
class Site::CataloguesController < ApplicationController
respond_to :js, :html
def index
produc_list # call method other controller
end
end
Run Code Online (Sandbox Code Playgroud)
other_controller.rb
class OtherController < ApplicationController
respond_to :js, :html
def produc_list
myObj = Catalagues.find(params[:id])
render :json => myObj
end
end
Run Code Online (Sandbox Code Playgroud) 我无法在现有表中添加外键,我的第一次迁移是:
public function up() {
Schema::create('clases_inventario', function($t) {
$t->increments('id');
$t->integer('grupos_inventario_id');
$t->integer('laboratorio_id');
$t->string('codigo', 4);
$t->string('descripcion', 64);
$t->boolean('estado')->default(true);
$t->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
我的第二次迁移是添加forein键
public function up() {
Schema::table('clases_inventario', function($table) {
$table->foreign('grupos_inventario_id')->references('id')->on('grupos_inventario');
});
}
Run Code Online (Sandbox Code Playgroud)
然后我运行php artisan migration并输出下一个错误
[Exception]
SQLSTATE[HY000]: General error: 1005 Can't create table 'bd_e_soft.#sql-818
_55' (errno: 150) (SQL: alter table `clases_inventario` add constraint clas
es_inventario_grupos_inventario_id_foreign foreign key (`grupos_inventario_
id`) references `grupos_inventario` (`id`)) (Bindings: array (
))
Run Code Online (Sandbox Code Playgroud)