我试图渲染为制定创业板登陆的看法,但我得到一个错误,下面的代码是我目前有:Rails的错误RESOURCE_NAME - 设计帮助路由和渲染
这是我views/users/shared/_links.html.erb
:
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
而且我config/routes.rb
:
Densidste::Application.routes.draw do
match 'user/edit' => 'users#edit', :as => :edit_current_user
match 'signup' => 'devise/users#new', :as => :signup
match 'logout' => 'devise/sessions#destroy', :as => :logout
devise_for :users do
get "login", :to => "devise/sessions#new"
end
resources :sessions
resources :users
devise_for :users
resources :aktivs
resources :taggingposts
resources :tags
resources :kommentares
resources :posts
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => "public#index"
end
在我的应用程序布局:
<%= render("users/shared/links") %>
我得到以下错误在_links.html.erb
部分:
NameError in Public#index
Showing C:/Rails/Densidste/app/views/users/shared/_links.erb where line #2 raised:
undefined local variable or method `resource_name' for #<#<Class:0x5db76c0>:0x5db6538>
Extracted source (around line #2):
1: <%- if controller_name != 'sessions' %>
2: <%= link_to "Sign in", new_session_path(resource_name) %><br />
3: <% end -%>
4:
5: <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
Trace of template inclusion: app/views/public/index.html.erb
Rails.root: C:/Rails/Densidste
最后,在我的应用程序控制器我有以下几点:
before_filter :resource_name
def resource_name
if user_signed_in?
current_user.name
else
:user
end
end
end
任何帮助,将不胜感激,谢谢!
我已更新我的问题如何创建一个before_filter:resource_name? – Hans 2011-05-10 19:37:08
我相信'resource_name'通常是类名的下划线版本。你可以试试'current_user.class.name.underscore'。这应该为'User'或'fancy_user'类型的对象给FancyUser类的对象提供'user'。 – andrewmitchell 2011-05-10 23:26:42
在[devise/controllers/url_helpers.rb](https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/url_helpers)中有关于这些“特定于资源”的帮助器方法的一些有用评论。 rb) – 2013-12-27 03:38:43