Release notes say that ruby-debug is installed by default. I'm using rvm. In my rails app I figured something as simple as script/server --debugger would suffice, but it complains that the ruby-debug gem isn't installed, suggests using gem install ruby-debug, which of course doesn't work (building native extensions) and is contrary to the docs anyway.
Just wondering if anyone's had any luck using the built in ruby-debug in jruby 1.5 and what one needs to do in order run jruby in debug mode.
Here's my output:
brad-robertsons-macbook-pro:trunk bradrobertson$ which ruby
/Users/bradrobertson/.rvm/rubies/jruby-1.5.1/bin/ruby
brad-robertsons-macbook-pro:trunk bradrobertson$ jruby --debug script/server --debugger
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
Hmm, it appears to work for me.
~/projects/jruby/yogi/test ➔ jruby --debug script/server --debugger
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Debugger enabled
=> Call with -d to detach
=> Ctrl-C to shutdown server
app/views/test/_test2.html.erb:3
<% 6.times do -%>
(rdb:3) next
app/views/test/_test2.html.erb:3
<% 6.times do -%>
(rdb:3) step
app/views/test/_test2.html.erb:4
<%= render :partial => "test3.html.erb" %>
(rdb:3) step
/Users/headius/projects/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:34
result = concat_without_safety(other_or_fixnum)
Given the following _test_2.html partial:
<div >
<% debugger -%>
<% 6.times do -%>
<%= render :partial => "test3.html.erb" %>
<% end -%>
</div>
How did you get JRuby?
I have the same problems with the RVM + JRuby combination. See my post on this for a work-around: http://wordsanddeeds.posterous.com/debugging-with-rvm-jruby
Related
I am a beginner of Ruby on Rails and web development. I am taking a online course and keep failing the lecture example.
My problem is my courses_controller, index action.
Controller: my_first_app/controllers/courses_controller.rb
class CoursesController < ApplicationController
def index
#search_term = 'jhu'
#courses = Coursera.for(#search_term)
end
end
Model: my_first_app/models/coursera.rb
class Coursera
include HTTParty
#default_options.update(verify: false) # Turn off SSL verification
base_uri 'https://api.coursera.org/api/catalog.v1/courses'
default_params fields: "smallIcon,shortDescription", q: "search"
format :json
def self.for term
get("", query: { query: term})["elements"]
end
end
View: my_first_app/views/index.html.erb
<h1>Search for - <%= #search_term %> </h1>
<table border = "1">
<tr>
<th>Image</th>
<th>Name</th>
<th>Description</th>
</tr>
<%= #courses.each do |course| %>
<tr>
<td><%= image_tag(course["smallIcon"]) %></td>
<td><%= course["name"] %></td>
<td><%= course["shortDescription"] %> </td>
</tr>
<% end %>
Routes: my_first_app/config/routes.rb
Rails.application.routes.draw do
get 'courses/index'
get 'greeter/hello'
get 'greeter/goodbye'
end
Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'httparty', '0.13.5'
end
I added the last gem to the Gemfile and run bundle, then I controlled +c to stopped and restarted the server and I got the error message:
JSON::ParserError in CoursesController#index
error message screenshot
I think it is saying that I parse a HTML instead of JSON, but I don't know how to fix it. Any help will be appreciated.
Original repository: https://github.com/jhu-ep-coursera/fullstack-course1-module3
According to the API documentation for Coursera, it looks like your base_uri might need to be:
base_uri 'https://api.coursera.org/api/courses.v1'
and then for fields in the default_params should (maybe) be:
default_params fields: "photoUrl,description", q: "search"
(changing the other occurrences of 'smallIcon' and 'shortDescription' with 'photoUrl' and 'description' in your app as well, since I don't see those fields in the api docs).
Once those changes are made you should end up going to urls like https://api.coursera.org/api/courses.v1?q=search&query=ruby&fields=photoUrl,description which is returning valid JSON. The current base_uri you are using is sending you to an HTML error page telling you Action not found. Since that's an HTML page, JSON can't parse it.
If you look at the date on the last commit in the Github repository you linked, the last commit was in November 2015, so nearly 2 years ago. Just super out of date, the API has probably changed a fair bit since then.
So...first time asking a question to StackOverflow...
I converted an existing Rails 4.2.5 app (using Ruby 2.2.4) to a Rails 5.1.3 app (using Ruby 2.4.1), following the Rails Guides and the RailsApps Project.
Firing up the development server produces:
Taruns-iMac:Play_Ball tarunchattoraj$ rails s
=> Booting Puma
=> Rails 5.1.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
which is what I would expect.
Navigating to localhost:3000, however, produces an the ActionController error:
Started GET "/" for 127.0.0.1 at 2017-08-13 11:05:38 -0400
(0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
ActionController::RoutingError (Couldn't find Api::KeepScoresHelper, expected it to be defined in helpers/api/keep_scores_helper.rb):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/welcome_controller.rb:1:in `<top (required)>'
I expected to see my app running on the page normally.
My Question:
What is causing this ActionController::RoutingError (Couldn't find...) and how to correct it?
This question seems to be on point. I tried the solution of "touching" all the helper files but to no avail.
When I converted from Rails 4.2.5 to 5.1.3, I ran $ rails app:update and I overwrote most files--those in which I didn't have code specific to my app, but I chose not to overwrite config/routes.rb.
config/routes.rb:
Rails.application.routes.draw do
resources :alerts
get 'games/decide_game_view' => 'games#decide_game_view', as: :decide_game_view
resources :games
resources :game_hitting_stats
resources :game_pitching_stats
resources :locations
resources :players
get 'welcome/index'
get 'welcome/about'
resources :users do
resources :players
end
resources :sessions, only: [:new, :create, :destroy]
resources :teams do
resources :notes
end
# namespace :api, defaults: {format: :http} do
namespace :api do
match '/texts', to: 'texts#preflight', via: [:options]
resources :texts, only: [:create]
match '/keepscore/teams', to: 'keep_scores#preflight', via: [:options]
get 'keepscore/teams' => 'keep_scores#get_teams', as: :get_teams
match '/keepscore/roster', to: 'keep_scores#preflight', via: [:options]
get 'keepscore/roster' => 'keep_scores#get_roster', as: :get_roster
match '/keepscore/post_game_stats', to: 'keep_scores#preflight', via: [:options]
post 'keepscore/post_game_stats' => 'keep_scores#post_game_stats', as: :post_game_stats
end
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
root 'welcome#index'
end
ActionController seems to be telling me that it can't find the KeepScoresHelper Module and that its looking in helpers/api/keep_scores_helper.rb. But that file exists See Pic of App Controller and Helper Tree Structure.
The contents of helpers/api/keep_scores_helper.rb:
module API::KeepScoresHelper
end
Gemfile:
source 'https://rubygems.org'
ruby "2.4.1"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.1.3'
gem 'puma'
gem 'pundit'
gem 'bcrypt'
gem 'active_model_serializers', '~> 0.10.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'bootstrap-sass'
gem 'figaro'
gem 'pry'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :test do
gem 'pundit-matchers', '~>1.0.1'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'listen'
gem 'byebug'
gem 'web-console', '~> 3.5.1'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'rspec-rails'
gem 'shoulda'
gem 'faker'
gem 'factory_girl_rails'
gem 'rails-controller-testing'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'sqlite3'
end
Of course any help is greatly appreciated...
In config/environments/development.rb, set:
config.action_controller.include_all_helpers = false
This returns Helpers to pre-Rails 5 behavior. Per RoR API, for Rails 5.1.3, "By default, each controller will include all helpers." Pre Rails 5, the controller would include a helper matched to its name. Making the setting as specified above returns to the Pre-Rails 5 behavior.
Adding in hopes of helping others that stumble across this.
Initial Trouble Shooting
I had this same issue when upgrading the same versions you mention in your question. I did upgrade from 4.2 to 5.0 first though then upgrade to 5.1.3 from there.
The first upgrade worked fine but I started receiving the same error message (e.g. uninitialized constant ActionController::RedirectBackError ... about not being able to find the helpers but this only happened when I jumped to rails 5.1.
I tried a lot of other fixes as outlined in this github issue as it seemed to be the same error but nothing worked and my paths all seemed to be correct (no discrepancies in path or casing).
My Fix
I ended up deleting all helpers and received a new error which lead me to finding the code in my app that was causing the problem.
# app/controllers/application_controller.rb
# Catch exceptions if :back is not set throughout the app. This is a fallback redirect if request.referer is not set.
rescue_from ActionController::RedirectBackError do |exception|
redirect_to key_activities_ministries_activities_path, alert: exception.message
end
That code was causing a Routing Error: uninitialized constant ActionController::RedirectBackError. But this error only appeared when I removed all of my helpers. I removed this code, put my helpers back, and restarted my server and everything worked as expected.
I'm building a rails 5 app using bootstrap for css styling, and for the most part it has been working fine. However, for some reason today, when I went to localhost:3000 in development, only the html is being rendered without any of the bootstrap styling I've added. I understand that this is a rather general/vague question, but is there any reason why this would happen?
Here is the output of the bundle install I ran last:
Using rake 11.3.0
Using concurrent-ruby 1.0.2
Using i18n 0.7.0
Using minitest 5.9.1
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 2.0.1
Using nio4r 1.2.1
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 7.1.4
Using execjs 2.7.0
Using bcrypt 3.1.11
Using sass 3.4.22
Using byebug 9.0.6
Using coffee-script-source 1.10.0
Using method_source 0.8.2
Using thor 0.19.1
Using debug_inspector 0.0.2
Using orm_adapter 0.5.0
Using unf_ext 0.0.7.2
Using ffi 1.9.14
Using multi_json 1.12.1
Using rb-fsevent 0.9.8
Using net-http-digest_auth 1.4
Using net-http-persistent 2.9.4
Using ntlm-http 0.1.1
Using webrobots 0.1.2
Using puma 3.6.0
Using bundler 1.13.6
Using ruby_http_client 3.0.0
Using tilt 2.0.5
Using sqlite3 1.3.12
Using turbolinks-source 5.0.0
Using tzinfo 1.2.2
Using nokogiri 1.6.8.1
Using rack-test 0.6.3
Using warden 1.2.6
Using sprockets 3.7.0
Using websocket-driver 0.6.4
Using mime-types 3.1
Using autoprefixer-rails 6.5.3
Using uglifier 3.0.3
Using font-awesome-sass 4.7.0
Using coffee-script 2.4.1
Using figaro 1.1.1
Using unf 0.1.4
Using rb-inotify 0.9.7
Using sendgrid-ruby 4.0.6
Using turbolinks 5.0.1
Using activesupport 5.0.0.1
Using loofah 2.0.3
Using mail 2.6.4
Using bootstrap-sass 3.3.7
Using domain_name 0.5.20161021
Using listen 3.0.8
Using rails-dom-testing 2.0.1
Using globalid 0.3.7
Using activemodel 5.0.0.1
Using jbuilder 2.6.0
Using spring 2.0.0
Using rails-html-sanitizer 1.0.3
Using http-cookie 1.0.3
Using activejob 5.0.0.1
Using activerecord 5.0.0.1
Using spring-watcher-listen 2.0.1
Using actionview 5.0.0.1
Using mechanize 2.7.5
Using actionpack 5.0.0.1
Using actioncable 5.0.0.1
Using actionmailer 5.0.0.1
Using railties 5.0.0.1
Using sprockets-rails 3.2.0
Using coffee-rails 4.2.1
Using responders 2.3.0
Using jquery-rails 4.2.1
Using material_icons 2.2.0
Using web-console 3.4.0
Using rails 5.0.0.1
Using sass-rails 5.0.6
Using devise 4.2.0
Bundle complete! 23 Gemfile dependencies, 83 gems now installed.
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
And the beginning lines of my application.scss:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
#import "bootstrap-sprockets";
#import "bootstrap";
#import "bootstrap/theme";
And the relevant part of my Gemfile:
# For scraping
gem 'mechanize'
# Devise
gem 'devise'
# bootstrap
gem 'bootstrap-sass', '~> 3.3.6'
# font-awesome
gem 'font-awesome-sass', '~> 4.7.0'
# for environment variables
gem 'figaro'
# sendgrid
gem 'sendgrid-ruby'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
EDIT: Per the request below, I've added the landing page, and also the application.html.erb in layouts:
<% content_for :top_content do %>
<div class="jumbotron">
<div class="container">
<h1>Welcome!</h1>
<p class="center"> Some Content. We're currently in development - please contact us using the link below if you are interested in learning more. </p>
<p class="center">Register or Login to get started</p>
<p class="center">
<%= link_to 'Register', new_user_registration_path, class: 'btn btn-primary btn-lg' %>
<%= link_to 'Log In', new_user_session_path, class: 'btn btn-primary btn-lg' %>
</p>
</div>
</div>
<% end %>
Appliction.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>TITLE</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>">
<%= value %>
</div>
<% end %>
</div>
<%= yield :top_content %>
<div class="container">
<h1><%= yield :header %></h1>
<%= yield %>
</div>
<div class = "container">
<%= render 'layouts/footer' %>
</div>
</body>
</html>
Not able to start rails5 with jruby, getting the following error.
gavinyap#gavin-ubuntu ~/Development/rails5app rails s
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from require at bin/rails:4)
Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-jdbcmysql-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
Backtrace for gem load error is:
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:13:in `<module:TypeCast>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:7:in `<module:Jdbc>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:4:in `< module:ConnectionAdapters>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:3:in `<top>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/column.rb:1:in `singleton cla
Versions of Jruby and Rails
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f
OpenJDK 64-Bit Server
VM 25.91-b14 on 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14 +jit [linux-x86_64]
Rails 5.0.0
The ActiveRecord JDBC gem has not been updated for Rails 5. Checking the project in GitHub shows some development activity early this year but there is no indication when a new gem will be released for Rails 5.
add gem 'activerecord-jdbcmysql-adapter', '~> 5.0.pre1' to your gemfile
I'm just trying to get the most basic of basic shell of a rails app running under 3.1, and I'm getting this weird error when I run bundle exec rake db:migrate-
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.)
All the posts that I've read here and elsewhere say I should be using the newer mysql2 adaptor for rails 3.1, so I have-
gem 'mysql2', '0.3.2'
in my gemfile. Some post have suggested using-
gem 'mysql2', '~> 0.3'
but that gets me the same error. The gem is installed at-
/Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/mysql2-0.3.2
It was suggested that I switch up that line in my gemfile again, this time to be-
gem 'mysql2', '< 0.3'
but when I do that, run bundle install, and then try to run migrations again, I get-
An error has occurred, all later migrations canceled:
undefined method `rows' for nil:NilClass
My complete migration file looks like this-
class CreatePlaces < ActiveRecord::Migration
def change
create_table :places do |t|
t.string :title
t.string :meta_description
t.string :permalink, :limit => 60
t.string :name, :limit => 60
t.string :address
t.string :state, :limit => 2
t.string :region, :limit => 3
t.float :latitude
t.float :longitude
t.text :description
t.boolean :active, :default => true
t.timestamps
end
add_index :places, [:permalink, :state, :region, :latitude, :longitude, :active], :name => 'places_index'
end
end
And the full output of running that migration is-
== CreatePlaces: migrating ===================================================
-- create_table(:places)
-> 0.0925s
-- add_index(:places, [:permalink, :state, :region, :latitude, :longitude, :active], {:name=>"places_index"})
-> 0.1097s
== CreatePlaces: migrated (0.2023s) ==========================================
rake aborted!
An error has occurred, all later migrations canceled:
undefined method `rows' for nil:NilClass
There are no later migrations, that's the only one, as this is an app that I'm just starting to try to get Rails 3.1 running properly. Dropping the database and recreating it gets me to the same place.
I am able to access Places from the console-
ruby-1.9.2-p180 :001 > Place
(0.3ms) SHOW TABLES
(0.1ms) SHOW TABLES
(1.1ms) describe `places`
=> Place(id: integer, title: string, meta_description: string, permalink: string, name: string, address: string, state: string, region: string, latitude: float, longitude: float, description: text, active: boolean, created_at: datetime, updated_at: datetime)
But when I actually try to do a find or anything on Places, I get the following error-
Place.find(:all)
ArgumentError: wrong number of arguments (3 for 2)
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/database_statements.rb:9:in `select_all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:470:in `find_by_sql'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation.rb:111:in `to_a'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:155:in `all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:105:in `find'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:437:in `find'
from (irb):2
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:45:in `start'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:8:in `start'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180#rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Anyone have any ideas? I've been digging for like 18 hours now, and just running in circles.
Thanks,
--Mark
Active Record has it's own requirements on which versions of mysql2 are compatible. Here's the line of code for Rails 3.1. You must use a version of mysql2 that satisfies these requirements.
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.)
This is saying Rails expects a mysql2 version greater than 0.3.6 and less than 0.4.0, but found version 0.3.2. If you change your Gemfile to request a version in this range then Active Record should be happy. Perhaps
gem 'mysql2', '0.3.6'
Don't forget to update your bundle after changing your Gemfile.
bundle update mysql2
I know this is a very old thread but because it still comes up in Google results a one of the first results I though I would updated it with I had to do work around this issue in newer versions of Rails.
The errors shows as:
Gem::LoadError: Specified 'mysql2' for database adapter,
but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile
followed by:
Gem::LoadError: can't activate mysql2 (< 0.5, >= 0.3.13),
already activated mysql2-0.5.2. Make sure all dependencies are
added to Gemfile.
I already had the gem added in my Gemfile as shown below:
group :production do
gem 'mysql2'
end
but I had to update it to prevent from picking up a version outside of the range indicated in the error message. Notice the '< 0.5' below:
group :production do
gem 'mysql2', '< 0.5'
end
Additionally, different versions of Rails set different min/max version restrictions for the MySQL gem:
From
https://github.com/brianmario/mysql2/issues/950#issuecomment-376375844
"Correct, Rails 4.x cannot use mysql2 0.5.x. The actual code would
work fine, but Rails 4 has a version restriction in place to prevent
use of mysql2 0.5.x. This is intentional, as it allows future changes
to the API without silently risking their use in older code not
prepared to use the new APIs. There's also nothing magic about the
version numbers -- it's totally by coincidence that Rails 4 uses
mysql2 0.4 and Rails 5 will be able to use mysql2 0.4 or 0.5."
This also had me pulling out my hair. To only reasonable solution I could get was to switch to the master branch of the mysql2 gem.
gem 'mysql2', :git => 'git://github.com/brianmario/mysql2.git'
After this update my Rails 3.1.0.rc5 application could start with MySQL. (At the time of this post the latest version of the gem was 0.3.6)
I have the same issue several times with an Redmine implementation.
I changed a gem line place on
RUBYGEM#VERSION/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql2_adapter.rb
In the line 3 change this
gem 'mysql2', '~> 0.3.10'
with this
gem 'mysql2', '~> 0.4.10' (or whatever version you need)
And all works fine
if anyone here is stuggling with this in 2022 with the new M2 book
"can't activate mysql2 (~> 0.3.10), already activated mysql2-0.5.2"
you have to update this file:
/usr/local/bundle/gems/activerecord-3.2.22.5/lib/active_record/connection_adapters/mysql2_adapter.rb:3
and change it to the version of the mysql gem you are using.
Pretty old question, so I'm assuming the original poster has already solved the issue. However, in case anyone is coming to this post trying to solve the first issue:
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.)
This is most likely occurring because you are not running your migrations via bundle exec. Try running bundle exec rake db:migrate.