In the first few rails app I setup for small apps to learn I used
RAILS_ENV=production rake db:setup
and it created the (mysql) tables on myapp_production
But this time I am not able to populate development or test DB. It just writes to production, also the app running on the Mongrel server writes to production DB but says it'S development environment on startup:
$ rails server
WARNING: This version of mysql2 (0.3.6) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
I don't use rvm here (tried on another box and guess I like it)
I am not sure how to troubeshoot this. And there is no error message.
You use old Rails version. mysql2 gem as of 0.3.0 do not support rails 3.0 and earlier. So you need either update rails to 3.1.x or higher or use gem "mysql2", "~> 0.2.7" in your Gemfile. See mysql2 gem page, search for "3.0" in your browser.
Maybe that's the reason.
Related
I'm trying to set up my local dev environment to match my team's. I can't upgrade Ruby/Rails/mysql2 (for the time being).
I know my local MySQL config is good (enough?) because I can create a new Rails project and run it just fine. I'm getting the same error if I run rake db:create or rails s or even start IRB and run require 'mysql2'.
I've googled the hell out of this. I was initially using MariaDB as my MySQL implementation locally, so I thought that might be screwing with the mysql2 gem. So I ripped out MariaDB and finally got MySQL 5.6 working (another team version we're locked into at the moment). After successfully upgrading to MySQL 5.6, I'm confident that's 100% not the issue.
I would expect if I had the wrong password for it to complain about the config somehow, but it's always the same.
uninitialized constant Mysql2::Client::SECURE_CONNECTION
Ruby (RVM): ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
Mysql2: 0.3.16
There have been some other version-related struggles, but nothing this strong. The only thing I've encountered that I haven't actually tried is building the mysql2 gem locally.
I would expect require 'mysql2' to at least load the gem. Neither Rails nor Rake will work with the gem at all. It's almost like it's missing some internal file.
following as discussion about this error in official gem, you should update version as
From
gem 'mysql2', '0.3.16'
to
gem 'mysql2', '0.3.17'
if you still met an error after you update version to 0.3.17, i think that you should update to 0.2.24
https://github.com/brianmario/mysql2/issues/603
I was trying to learn ruby on rails, so I installed the gem version 4.0.0, when I start my server, and go to localhost:8000, it brings me an error page with error message:
ActiveRecord::ConnectionNotEstablished.
I'm using sqlite3, not MySQL. Any help is appreciated.
edit: i fixed it, had to do with my database.yml
Make sure that you have installed sqlite3 gem: gem install sqlite3 or run bundle install if you have the gem listed on your Gemfile (which you should).
After that run the following commands:
rake db:create # creates the database
rake db:migrate # creates the tables based on your migration files
If the above two works fine, your application should be able to connect to the database. If not you probably have a configuration problem on your config/database.yml.
I am new to ruby on rails development. I am currently having difficulties generating a new rails controller. here is what I input into the terminal:
$ rails generate controller static_pages home help
here is the response I receive:
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:177
:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded.
Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
I am also using Heroku for production so I initially removed sqlite3 because Heroku cant use it by doing:
$ gem uninstall sqlite3
and I removed it from my gemfile and gemfile.lock. Was this a mistake? Any guidance would be much appreciated.
The error is because the config/database.yml file still has sqlite3 as the database adapter for the development database.
If you know which database you want to use for your local development database, set the appropriate database adapter in this file.
Heroku can't use sqlite3; however, you can use sqlite3 for your local development database, and specify postgres or mysql for production database.
Since you are a total beginner, I would recommend following the steps from a detailed tutorial as it is till you become familiar with the various concepts. Michael Hart's Rails Tutorial book is available for free online, and is a very good resource for beginner rails developers.
you cold try to rm Gemfile.lock and bundle install to reinstall your gems
Also make sure that the sqlite3 gem is in the development group
gem 'sqlite3', :group => :development
So that it will not be install on Heroku
This must be a simple question, but I could not find the answer by browsing this forum.
When I check rails version, it shows version 3.2.8
user#domain.com [~/rails_apps]# rails -v
Rails 3.2.8
user#domain.com [~/rails_apps]#
But when I start the server, it runs version 2.3.11
user#domain.com [~/rails_apps/myapp]# script/server -p12011
=> Booting Mongrel
=> Rails 2.3.11 application starting on http://0.0.0.0:12011
/home3/user/rails_apps/myapp/config/environment.rb:45: warning: already initialized constant RAILS_ENV
NOTE: SourceIndex.new(hash) is deprecated; From /usr/lib64/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:100:in `new'.
=> Call with -d to detach
=> Ctrl-C to shutdown server
What am I doing wrong?
If you application is a 2.x rails application, you need to complete some changes before upgrade to 3.x
You may have a look to railscast http://railscasts.com/?tag_id=27
On the other hand, you may want to upgrade your ruby to 1.9 using rvm
rails 3.x work better with ruby 1.9
Try following in your environment.rb
RAILS_GEM_VERSION = '3.2.8' unless defined? RAILS_GEM_VERSION
Check your Gemfile and make sure it is pointing to rails 3.2.8
Then run bundle or bundle update
I wonder if this is an old app, built originally upon rails 2.3.1 and periodically upgraded insitu. Instead of script/server, try rails server
And make sure your Gemfile contains reference to rails 3.2.8
Can't quite find the answer for my error in related posts.
I'm working my way through the on-line version of the Ruby on Rails Tutorial, Chapter 2
http://ruby.railstutorial.org/chapters/a-demo-app#top
and I'm near the bottom where I've created a small 2-table database and committed it to git. But it fails when I try to deploy with 'git push heroku master'. The same command worked previously before I added the tables to the app (and before I got Mongrel to work on the demo_app, I think).
My bundle includes Ruby 1.8.7, Mongrel 1.1.5 and sqlite3 1.3.3. I'm getting the line:
Installing mongrel (1.1.5) with native extensions /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions':ERROR: Failed to build gem native extension. (Gem:Installer::ExtensionBuildError).
How do I get around this problem? Can Heroku handle Mongrel at all? Or is it due to having a sqlite3 database? Why does the error mention Ruby1.9.2 when that's not in my bundle?
You don't need to use mongrel at all, and should simply remove it from your Gemfile. Whenever you see a reference to starting mongrel in your tutorial, just use ./script/server instead (or rails server if you're on Rails 3). It will run WebBrick, and that's good enough for development work.
If you really want to retain mongrel for local use you can group it as follows in Gemfile.
group :development do
gem "mongrel"
end
Note that you will likely still have to tell Heroku to not bundle your development gems or you'll run into the same error. If you're on the Cedar stack, then just get rid of the mongrel gem entirely.