Error while upgrading to Rails 2.3.11 (HashWithIndifferentAccess error) - ruby-on-rails

Whenever I attempt to create or update an environment that our app uses, I get the following:
NoMethodError (undefined method `base_url' for #<HashWithIndifferentAccess:0x107162f08>):
app/controllers/environments_controller.rb:64:in `check_base_url_for_https'
app/controllers/environments_controller.rb:56:in `update'
haml (3.0.22) lib/sass/plugin/rack.rb:41:in `call'
airbrake (3.0.4) lib/airbrake/rack.rb:27:in `call'
airbrake (3.0.4) lib/airbrake/user_informer.rb:12:in `call'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:82:in `start'
As I stated in the title, I recently upgraded to Rails 2.3.11. This error never occurred before. Here is the code in my environments_controller.rb that is being executed when the error occurs:
def check_base_url_for_https
#environment = params[:environment]
if /^https:\/\//i =~ #environment.base_url
#ajax_flash = "<ul class='notice'><li>The website you are trying to test is a secure site. If you are using self-signed SSL certificates please see our <a href='http://support.janova.us'>Support Site</a> and search for SSL for important tips on how to access your site.</li></ul>"
end
end
Does anyone know why this code (specifically the line if /^https:\/\//i =~ #environment.base_url no longer works in Rails 2.3.11?
I would like to add that the code in my app/models/environment.rb appears to be sound too:
def base_url
self[:base_url].try(:gsub, /\$/, '')
end
Does anyone see anything wrong with the code above?

I figured it out: params[:environment] was defined as a hash. Thank you, Frost, for forcing me to see this. Therefore, I changed the line #environment = params[:environment] to #environment = Environment.new(params[:environment]) and it worked.

Related

production-only error ActionView::Template::Error (can't convert Symbol into Integer)

I am attempting to deploy a site onto engineyard and I keep getting an error that seems to be a data formatting error. This only happens when deployed as production onto the server cluster. using the same DB and codebase locally or on a VPS we have no issues.
The errors seem to me to show that suddenly there is an array / hash type mismatch with some of the user data. It always seems to trace back to the model where it is tasked to get 'options'. The errors are triggered by the templates calling for access of checks on user attributes.
production log:
Completed 500 Internal Server Error in 32ms
** [Airbrake] Failure: Net::HTTPClientError
ActionView::Template::Error (can't convert Symbol into Integer):
18: = admin_user.username
19: = username_helper(admin_user)
20: %td= country_image admin_user
21: %td= admin_user.account_name
22: %td
23: - if admin_user.is_a?(Creative)
24: - if admin_user.is_juror?
app/models/user.rb:79:in `[]'
app/models/user.rb:79:in `has_option?'
app/models/contest_holder.rb:77:in `is_client_type?'
app/models/contest_holder.rb:81:in `is_agent?'
app/models/contest_holder.rb:70:in `ao_client_name'
app/models/contest_holder.rb:115:in `account_name'
app/views/admin/users/_users.html.haml:21:in `block in _app_views_admin_users__users_html_haml__845309245401675393_70184787547360'
trace:
ActionView::Template::Error: can't convert Symbol into Integer
Sample stack trace (show Rails)
/app/models/user.rb: 79:in `[]'
/app/models/user.rb: 79:in `has_option?'
…P/releases/20130814153250/app/models/contest_holder.rb: 77:in `is_client_type?'
…P/releases/20130814153250/app/models/contest_holder.rb: 81:in `is_agent?'
…P/releases/20130814153250/app/models/contest_holder.rb: 70:in `ao_client_name'
…P/releases/20130814153250/app/models/contest_holder.rb: 115:in `account_name'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb: 10:in `block in render_with_haml'
…ed_gems/ruby/1.9.1/gems/haml-4.0.3/lib/haml/helpers.rb: 89:in `non_haml'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb: 10:in `render_with_haml'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 68:in `block in call'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 56:in `each'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 56:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…ruby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/builder.rb: 49:in `call'
…VP/releases/20130814153250/lib/middleware/force_ssl.rb: 8:in `call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 35:in `block in call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 34:in `catch'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 34:in `call'
…ndled_gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb: 23:in `call'
…/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb: 25:in `call'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 210:in `context'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 205:in `call'
…es/20130814153250/config/initializers/session_store.rb: 10:in `call'
code from user.rb which seems to be the point of contact for the error:
def has_option?(option)
self.options[option] && self.options[option].to_s == "1"
end
an example of an options value:
--- !map:ActiveSupport::HashWithIndifferentAccess is_agent: "1"
Came to find out that the issue was an additional line break within the database file. Specifically the application uses serialized yaml data a fair amount. An additional line break had been added between the yaml hash key and value causing an error within the object. We initially tried creating a script to cleanse the db and came to find it seemed to be simply corrupt from the original db file.
This was what wrong with my case
Error : ActionView::Template::Error (can't convert Symbol into Integer)
Reason:
In my haml.
I was trying to access a property from a json object.
object[:key]
But actually it was a json array(Array of entities from active record where clause). I just filtered the first element.
Hope someone will find useful.

Rails: Fedena webpage has a redirect loop error. No method error undefined method config_value for nil:NilClass

i have installed fedena (rails application) in my website
http://www.technoadmin.com/
i have installed all plugins, gems, created and migrated the db.
i have created the symbolic link like this
ln -s ~/fedena/public ~/public_html
when visiting my webpage it shows
This webpage has a redirect loop
so please help me. i am a newbie.i have tried to install this
application for the last
one month. i think i have reached the final step. so please help me to
solve this error.i will be very thankful to you.
and my production logfile is
# Logfile created on Fri Jul 26 14:55:03 +0530 2013
Processing UserController#login (for 182.73.241.18 at 2013-07-26 15:00:48) [GET]
Parameters: {"action"=>"login", "controller"=>"user"}
[FedenaRescue] No method error undefined method `config_value' for nil:NilClass
NoMethodError (undefined method `config_value' for nil:NilClass):
app/controllers/application_controller.rb:319:in `set_user_language'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `send'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `evaluate_method'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:225:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:629:in `run_before_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:615:in `call_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `send'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:106:in `call'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:180:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/helper-scripts/passenger-spawn-server:99
Redirected to http://technoadmin.com/user/dashboard
These are the lines from 310 to 325 and i have only 325 lines in my application_controller.rb
return #local_tzone_time
end
private
def set_user_language
lan = Configuration.find_by_config_key("Locale")
I18n.default_locale = :en
Translator.fallback(true)
if session[:language].nil?
I18n.locale = lan.config_value
else
I18n.locale = session[:language]
end
News.new.reload_news_bar
end
end
the problem is with a method called config_value
NoMethodError (undefined method config_value' for nil:NilClass): app/controllers/application_controller.rb:319:inset_user_language'
so check your application_controller.rb on line 319 and post what's there
EDIT:
in your code (line 319), you're calling config_value on lan - but the error message is saying that lan has a nil value - so config_value can't be called on it.
earlier you have lan = Configuration.find_by_config_key("Locale") - so i'm guessing that rails can't find a config_key called "Locale" - but really I'm not sure. Did you write this code or was it generated by a gem?
I had this same issue when trying to setup Fedena on Ubuntu 20.04 using Docker.
Each time I try accessing the application on my browser on http://server-address:8080:/user/dashboard, I get a redirection. And then on my console, I get the error:
web_1 | Processing UserController#dashboard (for 103.89.5.96 at 2020-10-25 18:33:15) [GET]
web_1 | Parameters: {"controller"=>"user", "action"=>"dashboard"}
web_1 | [FedenaRescue] No method error undefined method `config_value' for nil:NilClass
web_1 |
web_1 | NoMethodError (undefined method `config_value' for nil:NilClass):
web_1 | app/controllers/application_controller.rb:342:in `set_user_language'
Here's how I fixed it:
Note: This is a temporary fix as I did not have a lot of time to dig into the codebase.
The issue emanates from this code in the app/controllers/application.rb file:
private
def set_user_language
lan = Configuration.find_by_config_key('Locale')
I18n.default_locale = :en
Translator.fallback(true)
I18n.locale = if session[:language].nil?
lan.config_value
else
session[:language]
end
News.new.reload_news_bar
end
I presume that the action set_user_language tries to set up a language for the user based on the default locale language set up on his/her machine/application or the session language, but then the config_value method called on Ian in lan.config_value seems to be Nil.
And this causes the redirect error since it is invoked in the app/controllers/application.rb using a before_filter:
before_filter :set_user_language
So it is called/invoked before any action is completed in the application.
A temporary fix will be to comment out the before_filter for it defined at the top of the app/controllers/application.rb file:
# before_filter :set_user_language
Now you can try accessing the page again.
You can as well consider running the command rake db:seed to seed the data in the db/seed.rb file into the database since it contains some important data that the application will need in order to run smoothly. And it also seems to contain the config_value data for the Configuration.
That's all.
I hope this helps

Ruby's `File.exist?` ThreadError

I am encountering errors when I am using Ruby's File.exist? method in middleware. I have no idea why.
This is the background. I am improving some old webapp which hosts around 100GB of photos and growing. I need to replicate production environment on my computer, but I don't want to download all those files. It would be great if app could check if given file exists in my filesystem and either serve it or redirect to production server.
I thought I could do simple rack app as middleware:
require 'rack/utils'
class FetchMissingPicturesMiddleware
def initialize(app)
#app = app
end
def call(env)
if env["PATH_INFO"].starts_with? "/system/attachments/" && !File.exist?(Rails.root.join('public').join(env["PATH_INFO"][1..-1]))
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, ""]
else
#app.call(env)
end
end
end
However, following error is thrown (not always, for some pictures it just works):
[2012-11-26 14:28:12] ERROR ThreadError: thread 0x10aed55e8 tried to join itself
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:31:in `lock'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:31:in `run'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/dispatcher.rb:108:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/rails/rack/static.rb:31:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:47:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in `each'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/rails/rack/log_tailer.rb:17:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/content_length.rb:13:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/handler/webrick.rb:48:in `service'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:82:in `start'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/handler/webrick.rb:14:in `run'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/commands/server.rb:111
script/server:6:in `require'
script/server:6
I am surprised with this issue because it's run inside mutex provided by Rack::Lock. Moving this middleware before Rack::Lock does not help. After removing File.exist? errors are gone. This is Ruby 1.8.7 with freshest (1.8.24) rubygems on Rails 2.3.9.
Thanks for your help.
Actually, the problem was bit different. The last element of the response array should be an array too.
wrong:
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, ""]
good:
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, []]

Twitter gem & Rails 3 - TypeError: can't convert Pathname into String

I'm trying to use the twitter gem in a rails 3 app but keep getting the following error:
TypeError: can't convert Pathname into String
Here's the code I'm trying to run:
class Tweet < ActiveRecord::Base
def self.test_tweet
Twitter.user_timeline("sferik").first.text
end
end
Here's the full error message:
TypeError: can't convert Pathname into String
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `initialize'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `new'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `connect'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:626:in `start'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:888:in `get'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/adapter/net_http.rb:59:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/request/url_encoded.rb:14:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/request/multipart.rb:13:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request/multipart_with_file.rb:17:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request/phoenix.rb:13:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request.rb:23:in `request'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request.rb:11:in `get'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/client/timelines.rb:208:in `user_timeline'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter.rb:17:in `method_missing'
from /home/shane/projects/bv_data/app/models/tweet.rb:5:in `test_tweet'
from (irb):1
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands/console.rb:45:in `start'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands/console.rb:8:in `start'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I get this error even when running the same code from the console:
Twitter.user_timeline("sferik").first.text
I created a blank test app with the same version of rails and the twitter gem and it runs no problem so I'm not sure what the problem is.
As I had this working before in the app I went back through my commits until I could find a point were it was working and what I did to break it.
So in case anyone happens to be in the same position what I had added was a fix_ssl.rb file in config/initializers which was to address a previous SSL connection issue. Removing this file allowed the Twitter gem to work correctly again.
config/initializers/fix_ssl.rb
require 'open-uri'
require 'net/https'
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
self.ca_file = Rails.root.join('lib/ca-bundle.crt')
self.verify_mode = OpenSSL::SSL::VERIFY_PEER
self.original_use_ssl = flag
end
end
end

Upgrading Rails 2.3.8 app to Rails 3.0.1, cannot call create on any models

I'm trying to upgrade from 2.3.8 to 3.0.1, but this problem has been plaguing me and preventing further progress for quite some time now. Any attempt to create something from my models (calling Subject.create! from the console, for example) always results in this error:
NoMethodError: undefined method `name' for 0:Fixnum
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:26:in `block in create'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:26:in `each'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:26:in `detect'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:26:in `create'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/writes.rb:24:in `call'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/session.rb:17:in `create'
from /.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/relation.rb:159:in `insert'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/relation.rb:14:in `insert'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/persistence.rb:271:in `create'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/timestamp.rb:47:in `create'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/callbacks.rb:281:in `block in create'
from /.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:413:in `_run_create_callbacks'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/callbacks.rb:281:in `create'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/persistence.rb:247:in `create_or_update'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/callbacks.rb:277:in `block in create_or_update'
from /.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:413:in `_run_save_callbacks'
... 1 levels...
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/persistence.rb:56:in `save!'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/validations.rb:49:in `save!'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/transactions.rb:242:in `block in save!'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/transactions.rb:289:in `block in with_transaction_returning_status'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/transactions.rb:204:in `transaction'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/transactions.rb:242:in `save!'
from /.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/validations.rb:34:in `create!'
from (irb):1
from /.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start'
from /.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start'
from /.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'ruby-1.9.2-p0
It would appear Arel is not getting a proper relation to work with, but I am lost as to what is causing this. Any ideas?
Thanks!
Ryan
What version of Ruby are you using? It should be either 1.8.7 or 1.9.2. I've had similar inexplicable issues with 1.9.1.
I would recommend putting some debug statements inside arel. Edit the engine.rb in the last line of the stack trace. I think you will have to restart the console (not just reload!) to see the changes in the arel file.
Here is the offending line in engine.rb:
attribute = relation.record.detect { |attr, _| attr.name.to_s == relation.primary_key.to_s }
Maybe try printing out the attr names and see if anything is passing thru the array detect method. Or print out the class of the "attr". The class should be "Arel::Attribute", but obviously a Fixnum is passing in there somehow.
attribute = relation.record.detect do |attr, _|
p attr.class
p attr.name
attr.name.to_s == relation.primary_key.to_s
end
Just a guess but I am thinking maybe a plugin/gem is interfering with something in your models. Are you using any dependencies that tie directly into ActiveRecord?
Another good exercise would be to create a blank Rails 3 app (with no gems or plugin dependencies) with one model and see if you get the same errors. That would rule out something in your development environment. Then if that works, then maybe you can start removing some of the dependencies one by one from the other app and see if one of them is causing the error.

Resources