如何覆盖设计可邀请的操作

时间:2013-08-12 15:33:48

标签: devise ruby-on-rails-3.2 devise-invitable

我在我的应用程序中使用设计可用的gem。如果用户存在于应用程序中并且他单击接受邀请链接,则应将其重定向到登录页面,如果新用户单击该链接,则应将其重定向到注册页面。我没有得到如何覆盖after_accept_path_for方法...在哪里以及如何覆盖此方法,有人可以帮助我吗? 关注https://github.com/scambra/devise_invitable/链接

2 个答案:

答案 0 :(得分:6)

我认为您可能需要重新阅读文档,您的问题已在文档中得到解答,而不是全部在一个地方。

以下是与您的问题有关的两个部分: https://github.com/scambra/devise_invitable#configuring-controllers https://github.com/scambra/devise_invitable#integration-in-a-rails-application

基本上你要为邀请添加一个控制器并为该控制器添加路由信息(app / controllers / users / invitations_controller.rb),如下所示:

class Users::InvitationsController < Devise::InvitationsController
  def after_accept_path_for
    "some path you define"
  end
end

然后你将改变你的routes.rb告诉设计使用你的邀请控制器,如:

devise_for :users, :controllers => { :invitations => 'users/invitations' }

答案 1 :(得分:1)

使用devise 2.1.2和devise_invitable 1.1.8,从邀请链接设置密码后你最终得到的页面取决于你在config / routes.rb中为你的设计资源设置的根路径,所以@trh的回答不适用于此版本(我尝试过但失败了)。从设计代码评论:

  # The default url to be used after signing in. This is used by all Devise
  # controllers and you can overwrite it in your ApplicationController to
  # provide a custom hook for a custom resource.
  #
  # By default, it first tries to find a valid resource_return_to key in the
  # session, then it fallbacks to resource_root_path, otherwise it uses the
  # root path. For a user scope, you can define the default url in
  # the following way:
  #
  #   map.user_root '/users', :controller => 'users' # creates user_root_path
  #
  #   map.namespace :user do |user|
  #     user.root :controller => 'users' # creates user_root_path
  #   end
  #
  # If the resource root path is not defined, root_path is used. However,
  # if this default is not enough, you can customize it, for example:
  #
  #   def after_sign_in_path_for(resource)
  #     stored_location_for(resource) ||
  #       if resource.is_a?(User) && resource.can_publish?
  #         publisher_url
  #       else
  #         super
  #       end
  #   end

在我的情况下,我有两个不同的命名空间,其中一个命名空间名为“portal”,我正在为用户使用“PortalUser”类。对于Rails 3.2,我只是在routes.rb中声明了这一行:

get "portal" => 'portal/dashboard#index', as: :portal_user_root

重要的注意事项是命名“portal_user_root”,它是PortalUser类名的下划线名称。只需设置此命名路由,您的devise_invitable就可以根据需要重定向。

相关问题