嗨,我有一个关于 Ruby on Rails 的应用程序..
这是我正在使用的 GEM。宝石文件
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 => '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
我正在寻找编写发送密码的文档(如果忘记了),但我找到了这个设计,允许用户更改密码
当我在登录所在的视图上插入此链接时
<%= link_to 'Change Password', edit_user_registration_path %>
我只是重定向到同一页面..我怎样才能制作这个视图?
我怎样才能定义这个视图的路径..不能写这个:(
更新:
在 controllers/admin/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' %>
改变我的问题..我怎样才能把它从管理员移到公开?
我只需要复制控制器的那部分..并将链接插入视图中吗?