问题
I'm bit confused by "easy" working with ruby on rails, cause I already spend three days by trying create an app.
I work on site5 hosting, and try to create new app. 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?
回答1:
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. 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. With rails 3, you should be using bundler for all gem management.
回答2:
This is how you do it.
gem list --local
Displays list of installed gems. Do you see mysql2 gem? If mysql2 is not installed run
gem install mysql2
You are now ready to launch a new rails app. 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. Navigate to the app directory and run
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. User will be "root" but without password. Enter the root password at all three places. You can also change user.
next 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 the terminal type
rails generate scaffold TableName name:string due:date etc...
rake db:migrate
...and you are done. Hope this helps.
回答3:
Have you tried running gem install mysql2
?
If that is not working, try following this tutorial
It looks like your problems are generated by the missing mysql gem.
Here is another question regarding its installation. See if any of the solutions from there apply to you too
回答4:
I ran into a similar problem. (I'm using rvm). I think I ran some code like:
The number after libmysqlclient
may be different. 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
来源:https://stackoverflow.com/questions/6450466/create-new-application-ruby-on-rails