我想更改
def url_after_create
'/'
end
的UsersController。如果我这样做:
class UsersController < Clearance::UsersController
protected
def url_after_create
'/dashboard'
end
end
当我试图注册一个新用户(在不重写时可以完美工作)时,我会得到以下信息:找不到UsersController的操作"index"——操作(post)是到"/users",似乎由于没有定义索引操作,它失败了。我该怎么办?
编辑:添加清除代码::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
位于路由中的这条线路match ':controller(/:action(/:id(.:format)))'
引起了故障。评论解决了这个问题。