您好我有一個應用程序在Ruby on Rails ..發送密碼設計在Ruby on Rails
這是我使用的GEMs。的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我得到這個
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 => '[email protected]',
: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
我一直在尋找文檔編寫發送密碼(如果忘記了),但我發現這個Devise, allowing users to change passwords
當我在視圖中插入此鏈接登錄是
<%= link_to 'Change Password', edit_user_registration_path %>
我我只是重定向到相同的頁面..我怎麼能使這個觀點?
如何可以定義路徑這一觀點..斜面寫這個:(
UPDATE:
在控制器/管理/ user_controller我發現這個
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' %>
改變我的問題..我怎麼能把這從管理到p ublic?
做我只需要複製控制器的一部分..和插入在視圖中的鏈接?
你嘗試了嗎? – vee
是的,但它的劑量工作,我認爲我沒有把這個「edit_user_registration_path」放在正確的地方,或寫出正確的def ..多數民衆贊成爲什麼我要求文件,甚至更多關於此。我真的是RoR上的noob – Monclee
設計已經有一個內置的「丟失密碼」功能,與「可恢復」選項(你正在使用)...你需要不同的東西? – Baldrick