我_header.html.erb是未定義的方法`每個」的零:NilClass中的Rails
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "Database Management", root_path, id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", root_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
SelectTable <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<% if $l == 1 %>
<% for items in @selectedtable %>
<li><%= link_to items, currenttable_path %> </li>
<% $gh = item %>
<% end %>
<% end %>
</ul>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
SelectDatabase <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<% for item in @selecteddatabase %>
<li><%= link_to item, currentdatabase_path %></li>
<% $gy = item %>
<% end %>
</ul>
<li><%= link_to "NewTable", newtable_path %></li>
<li><%= link_to "NewDatabase", newdatabase_path %></li>
<li><%= link_to "DeleteTable", deletetable_path %></li>
<li><%= link_to "DeleteDatabase", deletedatabase_path %></li>
<li><%= link_to "Connect", connect_path %></li>
<li><%= link_to "Disconnect", disconnect_path %></li>
<li><%= link_to "Administration", administration_path %></li>
<li><%= link_to "Quit", quit_path %></li>
</ul>
</nav>
</div>
</header>
application_controller.rb是
require 'mysql2'
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
$con = Mysql2::Client.new(host: "localhost", username: "root", password: "new_password", database: "mysql")
def header
rs = $con.query("SHOW databases")
i = 0
for y in rs
i = i + 1
end
c = 0
@selecteddatabase = Array.new(i)
for item in rs
@selecteddatabase[c] = item
c = c + 1
end
if $l == 1
ts = $con.query("SHOW tables")
i = 0
for y in ts
i = i + 1
end
k = 0
@selectedtable = Array.new(i)
for items in ts do
@selectedtable[k] = items
k = k + 1
end
end
end
end
application.html.erb是
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
錯誤是
NoMethodError在StatisPages#家
顯示 /home/tamal/rails_project/DatabaseManagement_app/app/views/layouts/_header.html.erb 其中線#25提出:
未定義的方法`每個」的零:NilClass
提取的源(圍繞線#25):
在@selecteddatabase%><%=的link_to逐項 <%$ GY =項%> <% 端%><%,currentdatabase_path%>
模板包含的跟蹤:app/views/layouts/application.html.erb
Rails.root:/ home/tamal/rails_project/DatabaseManagement_app Application Trace |框架跟蹤|全面跟蹤
應用程序/視圖/佈局/ _header.html.erb:25:在
_app_views_layouts__header_html_erb___324107568__651057508' app/views/layouts/application.html.erb:13:in
_app_views_layouts_application_html_erb__249465561_90094870'請求
爲什麼單擊「SelectDatabase」時不顯示下拉菜單。 –
如果您的原始問題已解決,並且您遇到新的無關聯問題,則應該提出一個新問題。 –