编辑:添加routes.rb文件 rails 3.2 ruby 1.92
我有一个标准的设计实现,让用户只输入他们的电子邮件地址。
当我在开发中运行应用程序时,它工作正常,当我在prod(rails s -e production)本地运行应用程序时,它工作正常。
然而,一旦我将它推送到heroku并尝试提交电子邮件地址,我会收到错误“电子邮件不能为空”
我提交电子邮件时本地登录
Started POST "/" for 127.0.0.1 at 2013-12-13 15:44:33 -0500
Processing by Devise::RegistrationsController#new as HTML
Parameters: {"authenticity_token"=>"3DQbumWdQ+HXTlrHo3cbCXWo2YVKDRXZLArypVyH05s="}
Rendered devise/registrations/new.html.erb within layouts/application (2.0ms)
Rendered layouts/_navigation.html.erb (1.0ms)
Rendered layouts/_messages.html.erb (0.0ms)
Completed 200 OK in 26ms (Views: 25.0ms | ActiveRecord: 0.0ms)
我提交电子邮件时来自heroku的日志条目
Processing by RegistrationsController#create as */*
Parameters: {"user"=>{"email"=>"nancy@drew.com"}}
Rendered devise/registrations/new.html.erb (31.8ms)
Completed 200 OK in 173ms (Views: 44.9ms | ActiveRecord: 21
的routes.rb
Myapp::Application.routes.draw do
authenticated :user do
root :to => 'home#index'
end
devise_scope :user do
root :to => "devise/registrations#new"
match '/user/confirmation' => 'confirmations#update', :via => :put, :as => :update_user_confirmation
end
devise_for :users, :controllers => { :registrations => "registrations", :confirmations => "confirmations" }
match 'users/bulk_invite/:quantity' => 'users#bulk_invite', :via => :get, :as => :bulk_invite
resources :users do
get 'invite', :on => :member
end
end
注册控制器
class RegistrationsController < Devise::RegistrationsController
# override #create to respond to AJAX with a partial
def create
build_resource
if resource.save
if resource.active_for_authentication?
sign_in(resource_name, resource)
(render(:partial => 'thankyou', :layout => false) && return) if request.xhr?
respond_with resource, :location => after_sign_up_path_for(resource)
else
expire_session_data_after_sign_in!
(render(:partial => 'thankyou', :layout => false) && return) if request.xhr?
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
render :action => :new, :layout => !request.xhr?
end
end
protected
def after_inactive_sign_up_path_for(resource)
# the page prelaunch visitors will see after they request an invitation
# unless Ajax is used to return a partial
'/thankyou.html'
end
def after_sign_up_path_for(resource)
# the page new users will see after sign up (after launch, when no invitation is needed)
redirect_to root_path
end
end
我的用户模型
class User < ActiveRecord::Base
rolify
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
# override Devise method
# no password is required when the account is created; validate password when the user sets one
validates_confirmation_of :password
def password_required?
if !persisted?
!(password != "")
else
!password.nil? || !password_confirmation.nil?
end
end
# override Devise method
def confirmation_required?
false
end
# override Devise method
def active_for_authentication?
confirmed? || confirmation_period_valid?
end
def send_reset_password_instructions
if self.confirmed?
super
else
errors.add :base, "You must receive an invitation before you set your password."
end
end
# new function to set the password
def attempt_set_password(params)
p = {}
p[:password] = params[:password]
p[:password_confirmation] = params[:password_confirmation]
update_attributes(p)
end
# new function to determine whether a password has been set
def has_no_password?
self.encrypted_password.blank?
end
# new function to provide access to protected method pending_any_confirmation
def only_if_unconfirmed
pending_any_confirmation {yield}
end