Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Rails中连接到单独的mysql数据库_Mysql_Ruby On Rails - Fatal编程技术网

在Rails中连接到单独的mysql数据库

在Rails中连接到单独的mysql数据库,mysql,ruby-on-rails,Mysql,Ruby On Rails,我正在尝试连接到一个单独的mysql数据库,而不是我的rails应用程序。我正在尝试连接到吉他标签数据库,以便用户可以搜索特定的歌曲 我已将我的database.yml配置为: tabs: adapter: mysql2 encoding: utf8 database: (dbname) username: (username) password: (pass) host: hostname.rds.amazona

我正在尝试连接到一个单独的mysql数据库,而不是我的rails应用程序。我正在尝试连接到吉他标签数据库,以便用户可以搜索特定的歌曲

我已将我的database.yml配置为:

     tabs:
      adapter: mysql2
      encoding: utf8
      database: (dbname)
      username: (username)
      password: (pass)
      host: hostname.rds.amazonaws.com
      port: 3306
到目前为止,我的模型是tab.rb:

    class Tab < ActiveRecord::Base

      self.abstract_class = true
      establish_connection ('tabs')

    end
最后,我的控制器

  class TabController < ApplicationController

    def listTabs
    @tabs = Tabs.all

    respond_to do |format|
          format.html # index.html.erb
          format.json { render json: @tabs }
    end
end

def showTabs

    @tabs = Tabs.find_by_sql "SELECT * FROM gp"

          respond_to do |format|
          format.html # index.html.erb
          format.json { render json: @statuses }
      end
    end


 end
我是rails新手,我真的很想让它发挥作用。如果你能帮我运行查询SELECT*From gp并将其显示在我的视图中,我将永远爱你


谢谢你的帮助

在您的模型中,名称为Tab,您在控制器选项卡中使用的名称是错误的,请使用Tab.all或Tab.find\u by\u sql