How to redefine inventive actions

I use inventive stone in my application. If the user exists in the application and he clicks on the invitation link, he must be redirected to enter another page, if a new user clicks the link he must redirect to register the page. I do not understand how I can override the after_accept_path_for method for this ... Where and how can I override this method, can someone help me with this? After https://github.com/scambra/devise_invitable/ link

+4
source share
2 answers

I think you might want to re-read the documentation, your question will be answered in the documents, but not all in one place.

Here are two sections that relate to your question: https://github.com/scambra/devise_invitable#configuring-controllers https://github.com/scambra/devise_invitable#integration-in-a-rails-application

Basically you are going to add a controller for invitations and add routing information for this controller (app / controllerlers / users / invitations_controller.rb) as follows:

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

Then you change your routes. rb to tell the developer what to use your invitation controller, for example:

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

With devise 2.1.2 and devise_invitable 1.1.8, the page you enter after setting the password from the invitation link depends on the fact that you set the root path for your development resource in config / routes.rb, so @trh answer doesn't works with this version (I tried and failed). From the development code comments:

  # 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 

In my case, I had two different namespaces with one namespace called "portal", which I used for this class "PortalUser". For Rails 3.2, I simply declared this line on my .rb routes:

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

An important note is the naming "portal_user_root", which is the underlined name of the class name PortalUser. Just setting this named route is all that your devise_invitable needs to redirect as desired.

+1
source

Source: https://habr.com/ru/post/1496624/


All Articles