Devise render sign => up/in form partials elsewhere in code

我只是一个虾纸丫 提交于 2019-12-04 07:20:27
David Colby

Take a look at the answer to this question: Devise form within a different controller

The form you are attempting to render with your Home controller relies on helpers defined by Devise that are not accessible from a non-Devise controller.

Adding the necessary helpers to your home_helper.rb should solve your problem:

def resource_name
:user
end

def resource
@resource ||= User.new
end

def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end

I'm using Devise 3.5.1 and I had to add resource_class as well to get the login form working on a different controller.

I added it to application_helper.rb so it applies to all of my controllers.

def resource_name
  :user
end

def resource
  @resource ||= User.new
end

def devise_mapping
  @devise_mapping ||= Devise.mappings[:user]
end

def resource_class
  devise_mapping.to
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!