【发布时间】:2017-04-05 04:21:37
【问题描述】:
我有 Devise 4.2.1 和 Rails 5.0.1。我正在尝试在registrations 以外的控制器中使用设计sign_in。有一堆方法没有定义,所以我不得不将它们添加为助手:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
def build_resource(hash=nil)
self.resource = resource_class.new_with_session(hash || {}, session)
# ^the source of the error^
end
def resource_class
devise_mapping.to
end
end
但现在我收到以下错误:
NoMethodError in Static#show
undefined method 'resource=' for (class)
我的代码中没有写“resource=”,当然也没有在错误指向的那一行(上面标记)。 我的服务器从哪里得到该错误?
另外,我想我只是使用标准的登录代码:
<%
build_resource({})
set_minimum_password_length
yield resource if block_given?
respond_with self.resource
%>
<% form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
...
【问题讨论】:
-
您将
sign_in方法从其默认位置之外移动的原因是什么? -
@LeonardoPrado 我正在尝试构建一个登录部分,我可以在我的应用程序的任何位置呈现。
-
Static#show 方法和 static/show.html.erb 中的内容是什么?
-
@JoeMorano 你可以使用任何你想要的部分,并把它放在你想要的任何地方,但仍然让它通过注册控制器。
标签: ruby-on-rails ruby devise ruby-on-rails-5