devise--undefined local variable or method `resource'
参考:https://stackoverflow.com/questions/4081744/devise-form-within-a-different-controller
增加下面的内容到application helper,因为在除了devise controller中使用,在其他地方使用,需要进行定义。
正如 Andres 所说,表单调用了由 Devise 指定的助手,因此当您从非 Devise 控制器访问 Devise 表单时,这些助手并不存在。 为了解决这个问题,您需要将以下方法添加到您希望在其下显示表单的控制器的帮助器类中。 或者,您可以将它们添加到您的应用程序助手中,以使它们在任何地方都可用。
As Andres says, the form calls helpers which are specified by Devise and so aren't present when you access a Devise form from a non-Devise controller.
To get around this, you need to add the following methods to the helper class of the controller you wish to display the form under. Alternatively, you can just add them to your application helper to make them available anywhere.
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end