howto parse nested json attributes with activeresource - ruby

i am trying to parse the following jsons response via activeresource in the padrino framework from a rest-api:
{"result":"Ok","resource":"ProjectRazor::Slice::Model","errcode":0,"command":"models_query_all","response":[{"#uri":"http://192.168.0.50:8026/razor/api/model/5nBqgTngqvxPIxVJJpdeQm","#callback":{},"#version":2,"#uuid":"5nBqgTngqvxPIxVJJpdeQm","#description":"Ubuntu Precise Model","#domainname":"andreasheumaier.de","#counter":0,"#broker_plugin":"agent","#root_password":"/7bbNwa6","#log":[],"#policy_bound":null,"#hostname_prefix":"firebird","#classname":"ProjectRazor::ModelTemplate::UbuntuPrecise","#osversion":"precise","#is_template":false,"#final_state":"os_complete","#node":null,"#req_metadata_hash":{"#domainname":{"validation":"^[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9](\\.[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])*$","example":"example.com","required":true,"description":"local domain name (will be used in /etc/hosts file)","default":"localdomain"},"#root_password":{"validation":"^[\\S]{8,}","example":"P#ssword!","required":true,"description":"root password (> 8 characters)","default":"test1234"},"#hostname_prefix":{"validation":"^[a-zA-Z0-9][a-zA-Z0-9\\-]*$","example":"node","required":true,"description":"node hostname prefix (will append node number)","default":"node"}},"#hidden":false,"#name":"ubuntu_precise","#label":"install_precise","#current_state":"init","#result":null,"#template":"linux_deploy","#noun":"model","#image_prefix":"os","#image_uuid":"4VuDj4mJDHP6bvWeztfXOO"}],"http_err_code":200}
I defined this models
class RazorJsonFormatter
include ActiveResource::Formats::JsonFormat
def decode(json)
ActiveResource::Formats::JsonFormat.decode(json)['response']
end
end
class Razor < ActiveResource::Base
include ActiveResource::Formats::JsonFormat
include ActiveResource::Extend::WithoutExtension
self.format = RazorJsonFormatter.new
self.site = "http://yellowbird:8026/razor/api/"
end
class RazorModel < Razor
set_collection_name 'model'
end
This gives following error:
RazorModel.all
NameError: wrong constant name #callback
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1428:in `const_defined?'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1428:in `find_or_create_resource_for'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1278:in `block in load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1264:in `each'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1264:in `load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1006:in `initialize'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:933:in `new'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:933:in `instantiate_record'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `block in instantiate_collection'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `collect!'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `instantiate_collection'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:901:in `find_every'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:814:in `find'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:826:in `first'
from (irb):27
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/lib/padrino-core/cli/base.rb:68:in `console'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:109:in `invoke'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/lib/padrino-core/cli/base.rb:73:in `c'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/bin/padrino:9:in `<top (required)>'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/bin/padrino:19:in `load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/bin/padrino:19:in `<main>'1.9.3p194
(...)
This either works with predifined ActiveResource schema. My current workaround is write all classes from scratch using rest-client
How can parse -or igore- the nested json attributes with activeresource?

Related

undefined method `rescue_responses' for ActionDispatch::ShowExceptions:Class (NoMethodError)

In my ruby 2.3.1, I get this error:
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/will_paginate-3.0.pre2/lib/will_paginate/railtie.rb:15:in `block in <class:Railtie>': uninitialized constant WillPaginate::Railtie::Forbidden (NameError)
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
from /home/bistipweb/config/environment.rb:5:in `<top (required)>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /home/bistipweb/config.ru:3:in `block in <main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /home/bistipweb/config.ru:in `new'
from /home/bistipweb/config.ru:in `<main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:78:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
My railtie.rb is:
require 'will_paginate'
require 'will_paginate/collection'
module WillPaginate
class Railtie < Rails::Railtie
initializer "will_paginate.active_record" do |app|
if defined? ::ActiveRecord
require 'will_paginate/finders/active_record'
WillPaginate::Finders::ActiveRecord.enable!
end
end
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
initializer "will_paginate.action_view" do |app|
require 'will_paginate/view_helpers/action_view'
ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
end
end
end
How can I fix it?
You don't have to add any initializer codes for hooking will_paginate into Rails project, if you are using recent will_paginate versions.
I see you are using 3.0.pre2 version, update it to 3.0.7 in your Gemfile, bundle update will_paginate and remove all the codes you added in railtie.rb, I think everything would be ok.
Try:
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
I do not find any reason for you to add railtie.rb file. I believe just adding the gem and using it in your view should work.

Cannot reindex with Searchkick

My database has over 3 million documents to be indexed. This is my setup:
Rails 4.2.0beta2 on Heroku. Using Searchkick with Found Heroku addon.
These are the models that I indexed:
class Item
searchkick text_start: [:n, :ot, :est]
def search_data
# as_json only: [:n, :ot, :est, :dst, :d, :a]
{
n: n,
ot: detail.ot,
est: detail.est,
dst: dst,
d: detail.d,
a: detail.a
}
end
end
class User
searchkick text_start: [:full_name]
def full_name
"#{first_name} #{last_name}"
end
def search_data
{
full_name: full_name
}
end
end
.. by doing rake searchkick:reindex:all.
Now, I've noticed that our Elasticsearch cluster has only indexed half of my documents (~1.5M). I asked our cluster provider if there is any limit on number of documents and confirmed that there isn't. I don't know why it stopped at 1.5M (instead of indexing all 3 million). However, now I'm trying to index everything again and watch out for errors or something alike and this is the first thing it comes out (before indexing anything):
NameError: undefined local variable or method `index' for #<Searchkick::Index:0x007fbb5308bf18>
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:192:in `block in import_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:648:in `yield_document'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:123:in `block in each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `block in each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/query.rb:77:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:122:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual.rb:20:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:189:in `import_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:158:in `reindex_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/model.rb:47:in `reindex'
from (irb):1
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
... 7 levels...
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/commands/rails.rb:6:in `call'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/command_wrapper.rb:38:in `call'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:183:in `block in serve'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:156:in `fork'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:156:in `serve'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:131:in `block in run'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:125:in `loop'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:125:in `run'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
Checking out cluster status once this error comes out, I see that a new index is created instead of "overriding" the old one: http://cl.ly/image/0I0v1a2T1N2W
What I'm doing wrong? Any ideas on how to solve this?
Thanks in advance.

How to fix ActiveRecord::DangerousAttributeError when checking pending migration in RSpec spec_helper?

Okay so this is a new one. RSPec. Rails 4.
This line is in my spec_helper.rb:
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
When I run a simple test (on an ActiveRecord model):
it { should respond_to :activity }
I get the following error & trace:
/Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord 4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?': version is defined by Active Record (ActiveRecord::DangerousAttributeError)
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `synchronize'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:793:in `current_version'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
from /projects/subset_of_projects/this_project_group/projectname/spec/spec_helper.rb:17:in `<top (required)>'
I'd added the paper_trail gem but not run the install/migrations. Simple and obvious really. But it wasn't an error I'd seen before so I'll post this so others who might run into it can check the obvious before wasting a long time on this.

mongoid uninitialized constant CarrierDomain (NameError)

I found another similar question and think I'm following the referenced directions from here but am still coming across this error.
As per the instructions I'm calling Mongoid.load!("path/to/your/mongoid.yml") in my ruby script, so I don't think it's that.
Maybe, as per the error message coming from inflector, it's an issue with how I'm defining CarrierDomain. I'm referencing a rails model from the Sinatra script. It's in a model file called carrier_domain.rb and the class is defined as CarrierDomain (class CarrierDomain). In fact, here is the entire class definition (it's a little one):
class CarrierDomain
include Mongoid::Document
embedded_in :carrier
field :country
field :name
field :prefix, default: ''
end
Here's the error message I'm getting:
/Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant CarrierDomain (NameError)
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/metadata.rb:606:in `klass'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builder.rb:39:in `klass'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:25:in `block in build'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:23:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:23:in `build'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:43:in `create_relation'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:26:in `__build__'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:156:in `block (3 levels) in getter'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/threaded/lifecycle.rb:125:in `_loading'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:156:in `block (2 levels) in getter'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:155:in `block in getter'
from /opt/cmf/app/models/carrier.rb:120:in `to_email_addresses'
from mta_connector.rb:151:in `block in <main>'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:645:in `yield_document'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:134:in `block (2 levels) in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:78:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:77:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:77:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:133:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:604:in `selecting'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:132:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual.rb:18:in `each'
from mta_connector.rb:139:in `<main>'
I had to explicitly require 'carrier_domain' in my Sinatra script.
I had thought that it would know to get the file, since it worked in the rails console (that is, I didn't need to require it in the rails console). Hmm.
Anyhoo, adding require 'carrier_domain' (i.e. the uninitialized constant) to my Sinatra script worked.

Undefined method 'strip' when deploying Sinatra Application using capistrano

I'm getting a strange error when running cap deploy:setup:
cap deploy:setup
Using ActiveModel validations.
Validations included SimpleRecord::Base
New Aws::SdbInterface using per_thread-connection mode
New Aws::S3Interface using per_thread-connection mode
/Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/command.rb:24:in `initialize': undefined method `strip' for Sinatra::Application:Class (NoMethodError)
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/command.rb:109:in `new'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/command.rb:109:in `else'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/actions/invocation.rb:144:in `block in run'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/command.rb:101:in `initialize'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/actions/invocation.rb:144:in `new'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/actions/invocation.rb:144:in `run'
from Capfile:9:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:93:in `instance_eval'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:93:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:89:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:86:in `block in load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:86:in `each'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/configuration/loading.rb:86:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/cli/execute.rb:65:in `block in load_recipes'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/cli/execute.rb:65:in `each'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/cli/execute.rb:65:in `load_recipes'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/cli/execute.rb:31:in `execute!'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/lib/capistrano/cli/execute.rb:14:in `execute'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/gems/capistrano-2.5.21/bin/cap:4:in `<top (required)>'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/bin/cap:19:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136#sinatra/bin/cap:19:in `<main>'
Any ideas on how to troubleshoot this?
It turns out the MyApp.rb did not actually define class MyApp. I added this:
class MyApp < Sinatra::Base
that error is now cleared.

Resources