Joh*_*nny 17 authentication ruby-on-rails devise
我正在尝试在我的Rails应用程序中使用Devise实现身份验证(Rails 2.3.8,Devise 1.0.7,在Windows Vista上运行的mongrel).但是我收到以下错误:
undefined local variable or method `devise_mapping' for #<ActionView::Base:0x6d63890>
Run Code Online (Sandbox Code Playgroud)
这是我使用自动生成的部分_devise_links.html.
<%- if controller_name != 'sessions' %>
<%= link_to t('devise.sessions.link'), new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to t('devise.registrations.link'), new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to t('devise.passwords.link'), new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to t('devise.confirmations.link'), new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && controller_name != 'unlocks' %>
<%= link_to t('devise.unlocks.link'), new_unlock_path(resource_name) %><br />
<% end -%>
Run Code Online (Sandbox Code Playgroud)
有想法该怎么解决这个吗?我假设devise_mapping变量没有包含在我的视图中,但我该怎么办呢?
joe*_*lvh 42
您可以添加辅助方法ApplicationHelper.确保使用正确的型号名称(在我的情况下,它:user代表User模型).
def devise_mapping
Devise.mappings[:user]
end
def resource_name
devise_mapping.name
end
def resource_class
devise_mapping.to
end
Run Code Online (Sandbox Code Playgroud)
2014年1月28日更新
Devise的主分支显示devise_mapping现在存储在请求中:
# Attempt to find the mapped route for devise based on request path
def devise_mapping
@devise_mapping ||= request.env["devise.mapping"]
end
Run Code Online (Sandbox Code Playgroud)
并且resource_name也有别名scope_name.有关详细信息,请参阅devise_controller.rb.
我意识到这个问题有点陈旧,但我想我弄清楚了为什么你不能只是渲染那个部分.您尝试呈现的部分内容是显示在sign_in/sign_up表单下方的链接的部分内容.
如果您想将这些链接添加到您的应用程序,Devise Wiki上的此页面将向您展示如何执行此操作,并且它涉及创建您自己的部分.
| 归档时间: |
|
| 查看次数: |
13042 次 |
| 最近记录: |