Create a new ruby ​​on rails application

I am a little confused by the β€œlight” work with ruby ​​on rails, because I have been trying to create an application for three days.

I work on site5 hosting and try to create a new application. step by step:

$ rails new app -d mysql $ gem install mysql $ gem install mysql2 

and after

 $ rake db:create 

he reports an error

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

I am google but still cannot fix the problem. Can anyone help?

+4
source share
4 answers

Running rails new app -d mysql will automatically add the necessary stones to your Gemfile, so you do not need to install them manually using the gem command. Try the following:

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

I suspect that the tutorial you are following is for an earlier version of Rails. With rails 3, you must use the bundler to manage all the gems.

+5
source

This is how you do it.

 gem list --local 

Displays a list of installed gems. Do you see mysql2 gem? If mysql2 is not installed, run

 gem install mysql2 

You are now ready to launch the new rails app. Go to the desired directory and run

 rails new my_app -d mysql 

This will create a new rails application in the my_app directory with mysql binding. Go to the application directory and run

 rake about 

If everything is fine, you should see the following

 Database adapter mysql2 

Leave your favorite text editor and go to config / database.yml. Note that there are three databases, one for development, testing, and production. The user will be root, but without a password. Enter the root password in all three places. You can also change the user.

then open mysql and create three databases

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

next in terminal type

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

... and you're done. Hope this helps.

+1
source

Have you tried running gem install mysql2 ?

If this does not work, try this tutorial.

It looks like your problems are due to the missing mysql gem.

Here is another question regarding its installation. See if any of the solutions is right for you.

0
source

I had a similar problem. (I am using rvm). I think I used some code, for example:

The number after libmysqlclient may vary. And the path may be different for you, 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 / stones / mysql2-0.2.7 / Library / mysql2 / mysql2.bundle

0
source

All Articles