在我的 Rails 应用程序中,我想接受“users/”链接之后的任何字符串。我该怎么做?那是例如。users/xyz
或者user/asdas
是可以接受的。我该怎么做呢?
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" &&
request.fullpath != "/users/sign_up" &&
request.fullpath != "/users/password" &&
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
好的,这是完整的故事。我已经实现了这一点,并且只有在用户获得批准后才允许用户登录。问题是我只需要为一种类型的用户做这件事,所以我registrations_controller.rb
通过覆盖它来实现它。
def create
build_resource(sign_up_params)
if resource.save
# nil
if !resource.has_role? :customer
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
resource.approved=true
resource.save
# nil
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
因此,只有客户可以直接获得批准,而其他人则不能。因此,当用户收到确认电子邮件并单击他们登录的链接但收到确认令牌无效错误时,这可能是由于即使在登录并转到我的根路径时页面也被重新路由回确认令牌已设置在after_sign_in_path
. 这就是为什么我正在尝试解决方法。
这是错误还是其他原因?