Create auxiliary resources of a resource and a resource in a user controller

I have expanded the standard Devise RegistrationsController using routes:

# use my own controller for devise registrations devise_for :users, :controllers => { registrations: 'registrations' } 

In this controller, I have a new_from_invitation method. This method displays the user registration form if the user comes from an invitation.

I copied the devize / registration / new.html.erb file. So my custom registration form looks like this:

 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 

This raises an ArgumentError because the resource is zero. Same as resource name. Somehow, resource and resource_name helpers are available in the standard development / registration / new method, but I can’t figure out how to do this. And therefore, cannot find a way to get these helpers for my custom method. Any help would be greatly appreciated!

+5
source share
1 answer

Add this to your application helper file:

  def resource_name :user end def resource @user ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end 
+3
source

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


All Articles