gpt4 book ai didi

mysql - Action Controller::Connection 在使用 mysql 在 ruby​​ on rails 中创建应用程序时未建立

转载 作者:行者123 更新时间:2023-11-30 22:57:06 26 4
gpt4 key购买 nike

我正在尝试在 ruby​​ on rails 中创建一个应用程序以及 mysql 连接。我已按照以下给定的步骤进行操作。

rails new ProjectName -d mysql

  1. 卸载您的 myslq2 gem:$gem uninstall mysql2

  2. 使用路径选项重新安装 mysql2 gem:gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector"'

  3. 将您在 C:\mysql-connector\lib 中找到的 libmysql.dll 复制到 C:\RailsInstaller\Ruby1.9.3\bin

  4. 在您的 Rails 应用程序中打开文件“Gemfile”并编辑它以启用 mysql2,方法是添加:gem 'mysql2'

  5. 启动您的 rails 服务器:$rails server

  6. 打开浏览器并转到 localhost:3000/

但是当我在浏览器窗口中运行服务器时,出现以下错误。

Action Controller::Connection not established while creating an application in ruby on rails with mysql

我的 config/database.yml 看起来像这样

default: &default  
adapter: mysql2
encoding: utf8
database: mp_development
pool: 5
username: root
password: qwe123
host: localhost


development:
<<: *default
adapter: mysql2
encoding: utf8
database: mp_development
pool: 5
username: root
password: qwe123
host: localhost

谁能尽快告诉解决方案。提前谢谢你

最佳答案

首先,纠正你的database.yml语法:

default: &default  
adapter: mysql2
encoding: utf8
database: mp_development
pool: 5
username: root
password: qwe123
host: localhost

development:
<<: *default

production:
<<: *default
database: mp_production

之后,确保你引用的数据库存在,运行:

rake db:setup # it will create db, if not exists

现在尝试运行您的服务器并浏览应用程序。

关于mysql - Action Controller::Connection 在使用 mysql 在 ruby​​ on rails 中创建应用程序时未建立,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com