0
我在RegistrationsController
中創建了新的after_sign_up
。 它看起來很有效。
但它錯誤First argument in form cannot contain nil or be empty
。
而且我可以找到after_sign_up
的resource
是nil
。但在after_inactive_sign_up_path_for
的資源是存在的。我怎麼能得到resource
全部到after_sign_up
?devise的我的after_sign_up工作。但它無法加載資源
registraions_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :force_ssl!
before_filter :require_update_ability, only: [:edit, :update, :destroy]
def create
super # Don't fix me!
puts 'user is created.'
end
def after_sign_up
puts resource
end
private
def force_ssl!
if Rails.env.production?
unless request.host == 'dashboard.userhabit.io' && request.ssl?
redirect_to :protocol => 'https', :host => 'dashboard.userhabit.io'
end
end
end
def require_update_ability
unless can? :update, current_user
flash[:error] = I18n.t 'messages.not_authorized'
redirect_to apps_path
end
end
protected
def after_inactive_sign_up_path_for(resource)
puts resource
after_sign_up_path(resource)
end
end
配置/ routes.rb中
devise_for :users, :controllers => {:registrations => 'users/registrations', :sessions => 'users/sessions', :passwords => 'users/passwords'}
devise_scope :user do
match 'users/after_sign_up' => 'users/registrations#after_sign_up', :as => 'after_sign_up', :via => :get
end
registrai附件/ after_sign_up.erb
<%= simple_form_for(resource, :as => resource_name, :url => after_sign_up_path(resource_name)) do |f| %>