Ruby on rails 在rails应用程序中显示数据库
控制器Ruby on rails 在rails应用程序中显示数据库,ruby-on-rails,sqlite,Ruby On Rails,Sqlite,控制器 class StaticPagesController“localhost”, :database=>“lab.db” ) 结束 我正在尝试将实验室数据库中的记录显示在我的网页的表格中。当前,当我导航到应该在其中显示记录的网页时,我遇到此错误。SQLite3::SQLException:没有这样的表::从“中选择“.”。当我在sqlite3中打开lab.db时,表和记录就在那里。我已经在这个rails应用程序中设置了另一个数据库,不确定这是否影响了我的显示。任何帮助都将不胜感激 尝试将
class StaticPagesController
查看
表,th,td{边框:1px纯黑色;}
th,td{padding:15px;}
实验室
地位
评论
型号
class-Lab“sqlite3”,
:host=>“localhost”,
:database=>“lab.db”
)
结束
我正在尝试将实验室数据库中的记录显示在我的网页的表格中。当前,当我导航到应该在其中显示记录的网页时,我遇到此错误。
SQLite3::SQLException:没有这样的表::从“
中选择“.”。当我在sqlite3中打开lab.db
时,表和记录就在那里。我已经在这个rails应用程序中设置了另一个数据库,不确定这是否影响了我的显示。任何帮助都将不胜感激 尝试将抽象类
和建立连接
位放在不同的基类(类外部
)中,然后从中扩展实验室:类实验室
我尝试了你的建议@TaylorCampbell,但没有乐趣。我现在得到了错误SQLite3::SQLException:没有这样的表:labs:从“labs”中选择“labs”。*。
class StaticPagesController < ApplicationController
def home
end
def labstatus
@labs = Lab.all
end
end
<head>
<style>
table, th, td { border: 1px solid black;}
th, td { padding: 15px;}
</style>
</head>
<table>
<thead>
<tr>
<th>Lab</th>
<th>Status</th>
<th>Comment</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @labs.each do |lab| %>
<tr>
<td><%= lab.Lab %></td>
<td><%= lab.Status %></td>
<td><%= lab.Comment %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
class Lab < ActiveRecord::Base
self.abstract_class = true
establish_connection(
:adapter => "sqlite3",
:host => "localhost",
:database => "lab.db"
)
end