简体   繁体   English

在rails上创建新的应用程序ruby

[英]create new application ruby on rails

I'm bit confused by "easy" working with ruby on rails, cause I already spend three days by trying create an app. 我很困惑“轻松”使用ruby on rails,因为我已经花了三天时间尝试创建应用程序。

I work on site5 hosting, and try to create new app. 我在site5托管上工作,并尝试创建新的应用程序。 step by step: 一步步:

$ rails new app -d mysql

$ gem install mysql

$ gem install mysql2

and after 之后

$ rake db:create

it report about error 它报告错误

Could not find gem 'mysql2 (~> 0.2.6, runtime)' in any of the gem sources listed in your Gemfile.

I google it, but still can't fix problem. 我谷歌它,但仍然无法解决问题。 Can anybody help? 有人可以帮忙吗?

Running rails new app -d mysql will automatically add the required gems to your Gemfile, so you shouldn't need to install them manually with the gem command. 运行rails new app -d mysql会自动将所需的gem添加到Gemfile中,因此您不需要使用gem命令手动安装它们。 Try the following: 请尝试以下方法:

$ rails new app -d mysql
$ cd app
$ bundle install
$ rake db:create

I suspect the tutorial you're following is for an older version of Rails. 我怀疑你所关注的教程是针对较旧版本的Rails。 With rails 3, you should be using bundler for all gem management. 使用rails 3,您应该使用bundler进行所有gem管理。

This is how you do it. 这就是你如何做到的。

gem list --local

Displays list of installed gems. 显示已安装宝石的列表。 Do you see mysql2 gem? 你看到mysql2 gem吗? If mysql2 is not installed run 如果没有安装mysql2运行

gem install mysql2

You are now ready to launch a new rails app. 您现在已准备好启动新的rails应用程序。 Go to the desired directory and run 转到所需目录并运行

rails new my_app -d mysql

This will create a new rails app in directory my_app with mysql binding. 这将在目录my_app中使用mysql绑定创建一个新的rails应用程序。 Navigate to the app directory and run 导航到app目录并运行

rake about

If every thing is fine you should see the following 如果一切都很好,你应该看到以下内容

Database adapter         mysql2

Fire your favourite text editor and go to config/database.yml Notice there are three databases, one each for development, test, and production. 触发您喜欢的文本编辑器并转到config / database.yml请注意,有三个数据库,分别用于开发,测试和生产。 User will be "root" but without password. 用户将是“root”但没有密码。 Enter the root password at all three places. 在所有三个地方输入root密码。 You can also change user. 您也可以更改用户。

next open mysql and create three databases 接下来打开mysql并创建三个数据库

mysql -u root -p
create database my_app_production;
create database my_app_test;
create database my_app_development;
exit

next in the terminal type 接下来是终端类型

rails generate scaffold TableName name:string due:date etc...
rake db:migrate

...and you are done. ......你完成了。 Hope this helps. 希望这可以帮助。

Have you tried running gem install mysql2 ? 你试过运行gem install mysql2吗?

If that is not working, try following this tutorial 如果这不起作用,请尝试遵循本教程

It looks like your problems are generated by the missing mysql gem. 看起来你的问题是由丢失的mysql gem生成的。

Here is another question regarding its installation. 是关于其安装的另一个问题。 See if any of the solutions from there apply to you too 看看那里的任何解决方案是否也适用于你

I ran into a similar problem. 我遇到了类似的问题。 (I'm using rvm). (我正在使用rvm)。 I think I ran some code like: 我想我运行了一些代码:

The number after libmysqlclient may be different. libmysqlclient之后的数字可能不同。 And the path may be different for you too, but the concept should be similar. 而且你的路径可能也不同,但概念应该是相似的。

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p136\\@rails3tutorial/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib~ / .rvm / gems / ruby​​-1.9.2-p136 \\ @ rails3tutorial / gems / mysql2-0.2.7 / lib /mysql2/mysql2.bundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM