尝试覆盖设计确认控制器时未初始化的常量ConfirmationsController错误

时间:2012-01-23 13:37:16

标签: ruby-on-rails-3

我试图在不使用内置设备确认控制器的情况下确认用户帐户,但我碰巧得到以下错误“未初始化的常量确认控制器”。以下是我的确认控制器类。

class ConfirmationsController < Devise::ConfirmationsController
def show
    @user = User.find_by_confirmation_token(params[:confirmation_token])
    if !@user.present?
        render_with_scope :new
    end
end

def confirm_account
    @user = User.find(params[:user][:confirmation_token])
    if @user.update_attributes(params[:user]) and @user.has_password?
        @user = User.confirm_by_token(@user.confirmation_token)
        flash[:notice] = "Hi " + @user.first_name + " your email has been verified. You can now start shopping and recommending other users to your supplier networks."
        redirect_to @user
    else
        render :action => "show"
    end
end
end

在我的routes.rb文件中,我有以下内容:

devise_for :users, :controllers => { :confirmations => "confirmations" } do
   match "confirm_account", :to => "confirmations#confirm_account"
 end

最后我有以下部分内容:

<p>Welcome <%= @user.first_name %>,</p><br/>
<%= form_for(resource, :url => confirm_account_path) do |f| %>
<%= f.label :email %>
<%= @user.email %>
<%= f.hidden_field :confirmation_token %>
<%= f.submit 'Confirm Account' %>
<p>Thank you for joining. Before you can purchase any item from your supplier or shared network, you will need to confirm your account first. Please follow the link below in order to confirm your account.</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p><br/>

<p>Yours faithfully.</p>
<%end%>

1 个答案:

答案 0 :(得分:1)

可以根据您的需要轻松修改设计。这是一个类似的主题,可能对您有所帮助: Override devise registrations controller