在清除中覆盖UsersController的方法

时间:2012-01-31 23:07:41

标签: ruby-on-rails override clearance

我想改变

  def url_after_create
    '/'
  end
清除中 UsersController

。如果我这样做:

class UsersController < Clearance::UsersController

  protected

  def url_after_create
    '/dashboard'
  end


end

当我尝试注册一个新用户时,在没有覆盖的情况下工作正常,我得到以下结果:无法找到UsersController的动作'index' - 动作(post)是'/ users '似乎由于未定义索引操作,因此失败。我该怎么办?

编辑:添加了 Clearance :: UsersController

的代码
class Clearance::UsersController < ApplicationController
  unloadable

  skip_before_filter :authorize,   :only => [:new, :create]
  before_filter :redirect_to_root, :only => [:new, :create], :if => :signed_in?

  def new
    @user = ::User.new(params[:user])
    render :template => 'users/new'
  end

  def create
    @user = ::User.new(params[:user])
    if @user.save
      sign_in(@user)
      redirect_back_or(url_after_create)
    else
      flash_failure_after_create
      render :template => 'users/new'
    end
  end

  private

  def flash_failure_after_create
    flash.now[:notice] = translate(:bad_email_or_password,
      :scope   => [:clearance, :controllers, :passwords],
      :default => "Must be a valid email address. Password can't be blank.")
      end

  def url_after_create
    '/'
  end
end

1 个答案:

答案 0 :(得分:0)

位于路线中的这一行match ':controller(/:action(/:id(.:format)))'导致了问题。评论解决了它。