Ruby on rails 3 铁路3号及;设计:注销时出错
问题已解决 克劳斯托弗他的回答解决了这个问题Ruby on rails 3 铁路3号及;设计:注销时出错,ruby-on-rails-3,devise,Ruby On Rails 3,Devise,问题已解决 克劳斯托弗他的回答解决了这个问题 问题是,当我有或在我的layouts/application.html.erb中时,我无法注销 当我从application.html.erb中删除这一行时,我可以无误地注销。 我在谷歌上搜索过,但找不到关于这个问题的任何信息 My application.html.erb: <!DOCTYPE html> <html id="html"> <head> <title><%= content_
问题是,当我有或在我的layouts/application.html.erb中时,我无法注销 当我从application.html.erb中删除这一行时,我可以无误地注销。 我在谷歌上搜索过,但找不到关于这个问题的任何信息 My application.html.erb:
<!DOCTYPE html>
<html id="html">
<head>
<title><%= content_for?(:title) ? yield(:title) : "Contractbeheersysteem" %></title>
<%= stylesheet_link_tag "application", "simple_form", "gegevens", "drop-down-menu", "table", :media => "all" %>
<%= javascript_include_tag "autocomplete-rails.js" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>
<%= javascript_include_tag 'jquery.dataTables.min' %>
<%= csrf_meta_tag %>
<%= yield(:head) %>
</head>
<body>
<body link="#999" vlink="black" alink="black">
<div id="menu">
<ul id="drop-down-menu">
<li><%= link_to "Home Page", home_index_path, :class => current_page?(home_index_path) ? "current" : "" %></li>
<li><%= link_to "Bedrijfsgegevens", bedrijfsgegevens_path, :id => 'bednav' %>
<ul>
<li><%= link_to "Nieuw Bedrijf toevoegen", new_bedrijfsgegeven_path %></li>
</ul>
</li>
<li><%= link_to "Contactpersonen", contactpersoons_path, :id => 'contanav' %>
<ul>
<li><%= link_to "Nieuw Contactpersoon", new_contactpersoon_path %></li>
</ul>
</li>
<li><%= link_to "Contractgegevens", contractgegevens_path(@contractgegevens), :id => 'contrnav' %>
<ul>
<li><%= link_to "Nieuwe Contractgegevens", new_contractgegeven_path %></li>
</ul>
<li><%= link_to "Contactformulier", contact_index_path, :id => 'formnav' %> </li>
<% if user_signed_in? %>
<li><%= link_to "My Account", users_path(@users) %>
<ul>
<li><%= link_to "Uitloggen", destroy_user_session_path, :method => :delete %>
<li><%= link_to "Gebruikers", user_registration_path %>
</ul>
<% else %>
<li><%= link_to "Inloggen", new_user_session_path %>
<ul>
<li><%= link_to "Registreren", new_user_registration_path %>
</ul>
<% end %>
</ul>
<p class="clear_all"></p>
</div>
<div id="login">
Inlogd als: <%= current_user.username %>
</div>
<div id="content">
<hr>
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
<%= yield %>
</div>
<div id="footer">
<hr color="#999", width="100%">
<h4>
<b><a href="http://piterjelles.nl">Piter Jelles</a> © 2012 </b> | <a href="http://rubyonrails.org">Ruby on Rails </a>
</h4>
</div>
</font>
</body>
</div>
</html>
“全部”%>
- 当前页面?(主页索引路径)?“当前”:“%>
- “bednav%”
- 'contanav'>
- “contrnav%”
- 'formnav'>
-
- :删除%>
-
-
-
在日志中:
“flash{name}”%>
注意:我来自荷兰,因此我的应用程序中有荷兰语单词。html.erb您需要检查是否存在当前用户,如: 或
当您注销时,当前用户将返回
nil
。在nil
上调用方法将返回一个错误
1.9.3p125 :002 > nil.username
NoMethodError: undefined method `username' for nil:NilClass
您必须检查当前用户是否返回非nil的内容。您可以使用
<%= current_user.username if current_user %>
谢谢,作为初学者,这对我来说有点棘手。我希望其他人会对这个帖子有所了解。这也是对的,但克劳斯托弗的回答对于rails新手来说更容易理解。