I am working on a project with GraphQL for the first time and I've hit a bit of a snag I can't figure out. I have a business model, a user model and an industry model. The business model belongs to both of the other models. Scaffolded view operations run as expected, but when I run a Graph query on businesses and include either of the other two models, it errors out with
undefined method `map' for #User:0x00007fadeb73f140>\nDid you mean?
tap
Here is my definition in query_type.rb:
# get all businesses
field :businesses, [Types::BusinessType], null: false, description: "List of all businesses"
def businesses
Business.all
end
And here is my BusinessType:
module Types
class BusinessType < BaseObject
field :id, ID, null: false
field :name, String, null: false
field :zip_code, String, null: true
field :growth_stage, String, null: true
field :annual_revenue, Integer, null: true
field :first_name, String, null: false
field :last_name, String, null: false
field :email, String, null: false
field :phone, String, null: false
field :industry, type: [Types::IndustryType], null: true
field :user, type: [Types::UserType], null: true
end
end
And here is my Graph query:
{
businesses {
id
name
growthStage
annualRevenue
firstName
lastName
email
phone
zipCode
user {
email
}
industry {
name
}
}
}
here is the stack trace:
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activemodel-6.0.0/lib/active_model/attribute_methods.rb:431:in `method_missing'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema/member/instrumentation.rb:93:in `proxy_to_depth'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema/member/instrumentation.rb:85:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/field.rb:248:in `resolve'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:321:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema/middleware_chain.rb:49:in `invoke_core'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema/middleware_chain.rb:38:in `invoke'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:129:in `block in resolve_field'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `block in trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:76:in `call_tracers'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:128:in `resolve_field'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:92:in `block in resolve_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:85:in `each'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:85:in `resolve_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:284:in `resolve_value'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:278:in `resolve_value'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:213:in `continue_resolve_field'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:184:in `continue_or_wait'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:263:in `block in resolve_value'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:256:in `each'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:256:in `resolve_value'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:278:in `resolve_value'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:213:in `continue_resolve_field'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:184:in `continue_or_wait'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:157:in `resolve_field'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:92:in `block in resolve_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:85:in `each'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:85:in `resolve_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:56:in `block in resolve_root_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `block in trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:76:in `call_tracers'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:49:in `resolve_root_selection'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/execute.rb:31:in `begin_query'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:112:in `begin_query'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:84:in `block in run_as_multiplex'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:83:in `map'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:83:in `run_as_multiplex'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:62:in `block (2 levels) in run_queries'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:186:in `block in instrument_and_analyze'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:29:in `block (2 levels) in apply_instrumenters'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:46:in `block (2 levels) in each_query_call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:41:in `each_query_call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:45:in `block in each_query_call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:174:in `instrument_and_analyze'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:61:in `block in run_queries'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `block in trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:76:in `call_tracers'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/tracing.rb:62:in `trace'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:59:in `run_queries'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/execution/multiplex.rb:49:in `run_all'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema.rb:392:in `block in multiplex'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema.rb:1279:in `with_definition_error_check'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema.rb:391:in `multiplex'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/graphql-1.9.12/lib/graphql/schema.rb:368:in `execute'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/forwardable.rb:230:in `execute'",
"/private/var/sites/clients/army_of_bees/finsync/ap-backend-temp/app/controllers/graphql_controller.rb:12:in `execute'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/abstract_controller/base.rb:196:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/rendering.rb:30:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/abstract_controller/callbacks.rb:42:in `block in process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/callbacks.rb:135:in `run_callbacks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/abstract_controller/callbacks.rb:41:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/rescue.rb:22:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/notifications.rb:180:in `block in instrument'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/notifications/instrumenter.rb:24:in `instrument'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/notifications.rb:180:in `instrument'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/instrumentation.rb:32:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.0/lib/active_record/railties/controller_runtime.rb:27:in `process_action'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/abstract_controller/base.rb:136:in `process'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionview-6.0.0/lib/action_view/rendering.rb:39:in `process'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal.rb:191:in `dispatch'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal.rb:252:in `dispatch'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/routing/route_set.rb:51:in `dispatch'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/routing/route_set.rb:33:in `serve'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/router.rb:49:in `block in serve'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/router.rb:32:in `each'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/router.rb:32:in `serve'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/routing/route_set.rb:837:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/tempfile_reaper.rb:15:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/etag.rb:25:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/conditional_get.rb:38:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/head.rb:12:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/http/content_security_policy.rb:18:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:232:in `context'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:226:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/cookies.rb:648:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.0/lib/active_record/migration.rb:567:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/callbacks.rb:101:in `run_callbacks'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/callbacks.rb:26:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/executor.rb:14:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/web-console-4.0.1/lib/web_console/middleware.rb:132:in `call_app'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/web-console-4.0.1/lib/web_console/middleware.rb:28:in `block in call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/web-console-4.0.1/lib/web_console/middleware.rb:17:in `catch'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/web-console-4.0.1/lib/web_console/middleware.rb:17:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/rack/logger.rb:38:in `call_app'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/rack/logger.rb:26:in `block in call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/tagged_logging.rb:80:in `block in tagged'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/tagged_logging.rb:28:in `tagged'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/tagged_logging.rb:80:in `tagged'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/rack/logger.rb:26:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/request_id.rb:27:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/runtime.rb:22:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/executor.rb:14:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/static.rb:126:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/host_authorization.rb:83:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-cors-1.0.3/lib/rack/cors.rb:95:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/engine.rb:526:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/puma-3.12.1/lib/puma/configuration.rb:227:in `call'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:660:in `handle_request'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'",
"/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'"
I was able to resolve this by changing the following line in business_type.rb:
field :user, type: [Types::UserType], null: false
to
field :user, Types::UserType, null: false
UPDATE: It turns out that the first example should only work with lists of objects and the second with single objects
I've written a script that imports paginated JSON data from an api, encodes the data to UTF-8 and then writes it to a file.
I need to iterate over the data in the file to create records in my database, but am running to an error loading the file so I can do so.
The stack trace isn't telling me much about what's wrong; any help would be greatly appreciated!
code:
require 'net/http'
require 'uri'
require 'json'
require 'faker'
#imports APR User data from the zendesk api, iterates through it and populates the database with it.
uri = URI.parse("https://aprtechsupport.zendesk.com/api/v2/users.json")
request = Net::HTTP::Get.new(uri)
request.content_type = "application/json"
request.basic_auth("cbradford#blah.com", "blah32")
req_options = {
use_ssl: uri.scheme == "https",
}
#response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
res = #response.body
res.force_encoding("utf-8")
resEncoded = JSON.parse(res)
users = resEncoded
#data = {}
#data.merge(users)
results = []
results << resEncoded
puts results
while users["next_page"]
newUri = users["next_page"]
uriLoop = URI.parse(newUri)
puts newUri
requestLoop = Net::HTTP::Get.new(uriLoop)
requestLoop.content_type = "application/json"
requestLoop.basic_auth("cbradford#blah.com", "blah32")
req_optionsLoop = {
use_ssl: uriLoop.scheme == "https",
}
#responseLoop = Net::HTTP.start(uriLoop.hostname, uriLoop.port, req_optionsLoop) do |http|
http.request(requestLoop)
end
dataEncoded = #responseLoop.body
dataEncoded.force_encoding("utf-8")
resLoop = JSON.parse(dataEncoded)
results << resLoop
updateUri = resLoop["next_page"]
users["next_page"] = updateUri
end
puts "hash created Successfully!"
puts results
File.write('blahzendeskusers1.json', results)
puts "File Created Successfully!"
file = File.read('blahzendeskusers1.json')
usersLoop = JSON.load(file)["users"]
usersLoop.each do |a|
User.find_or_create_by(:zendesk_id_int => a["id"], :url => a["url"], :name => a["name"], :email => a["email"],
:phone => a["phone"], :role => a["role"], :default_group_id => a["default_group_id"], :external_id => a["external_id"],
:tags => a["tags"]
)
end
stack trace:
> /Users/christopherbradford/.rbenv/versions/2.3.1/lib/ruby/2.3.0/json/common.rb:156:in
> `parse'
> /Users/christopherbradford/.rbenv/versions/2.3.1/lib/ruby/2.3.0/json/common.rb:156:in
> `parse'
> /Users/christopherbradford/.rbenv/versions/2.3.1/lib/ruby/2.3.0/json/common.rb:335:in
> `load'
> /Users/christopherbradford/railsProjects/aprzendeskdata/db/seeds.rb:84:in
> `<top (required)>'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:286:in `load'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:286:in `block in load'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:258:in `load_dependency'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.5/lib/active_support/dependencies.rb:286:in `load'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/railties-5.1.5/lib/rails/engine.rb:549:in
> `load_seed'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.5/lib/active_record/tasks/database_tasks.rb:270:in
> `load_seed'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.5/lib/active_record/railties/databases.rake:184:in
> `block (2 levels) in <top (required)>'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:271:in
> `block in execute'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:271:in
> `each'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:271:in
> `execute'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:213:in
> `block in invoke_with_call_chain'
> /Users/christopherbradford/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in
> `mon_synchronize'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:193:in
> `invoke_with_call_chain'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/task.rb:182:in
> `invoke'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:160:in
> `invoke_task'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:116:in
> `block (2 levels) in top_level'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:116:in
> `each'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:116:in
> `block in top_level'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:125:in
> `run_with_threads'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:110:in
> `top_level'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:83:in
> `block in run'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:186:in
> `standard_exception_handling'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/lib/rake/application.rb:80:in
> `run'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/exe/rake:27:in
> `<top (required)>'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/bin/rake:23:in `load'
> /Users/christopherbradford/.rvm/gems/ruby-2.4.1/bin/rake:23:in
> `<main>' Tasks: TOP => db:seed
Sample File Data:
{"users"=>[{"id"=>360403052546, "url"=>"https://aprtechsupport.zendesk.com/api/v2/users/360403052546.json", "name"=>"Caller +1 (650) 434-4313", "email"=>nil, "created_at"=>"2018-03-05T19:36:00Z", "updated_at"=>"2018-03-05T19:36:00Z", "time_zone"=>"Pacific Time (US & Canada)", "phone"=>"+16504344313", "shared_phone_number"=>false, "photo"=>nil, "locale_id"=>1, "locale"=>"en-US", "organization_id"=>nil, "role"=>"end-user", "verified"=>true, "external_id"=>nil, "tags"=>[], "alias"=>nil, "active"=>true, "shared"=>false, "shared_agent"=>false, "last_login_at"=>nil, "two_factor_auth_enabled"=>false, "signature"=>nil, "details"=>nil, "notes"=>nil, "role_type"=>nil, "custom_role_id"=>nil, "moderator"=>false, "ticket_restriction"=>"requested", "only_private_comments"=>false, "restricted_agent"=>true, "suspended"=>false, "chat_only"=>false, "default_group_id"=>nil, "user_fields"=>{}}, {"id"=>360404721566, "url"=>"https://aprtechsupport.zendesk.com/api/v2/users/360404721566.json", "name"=>"renglehart", "email"=>"renglehart#apr.com", "created_at"=>"2018-03-06T00:29:39Z", "updated_at"=>"2018-03-07T19:00:58Z", "time_zone"=>"Pacific Time (US & Canada)", "phone"=>nil, "shared_phone_number"=>nil, "photo"=>nil, "locale_id"=>1, "locale"=>"en-US", "organization_id"=>nil, "role"=>"end-user", "verified"=>true, "external_id"=>nil, "tags"=>[], "alias"=>nil, "active"=>true, "shared"=>false, "shared_agent"=>false, "last_login_at"=>"2018-03-07T19:00:58Z", "two_factor_auth_enabled"=>false, "signature"=>nil, "details"=>nil, "notes"=>nil, "role_type"=>nil, "custom_role_id"=>nil, "moderator"=>false, "ticket_restriction"=>"requested", "only_private_comments"=>false, "restricted_agent"=>true, "suspended"=>false, "chat_only"=>false, "default_group_id"=>nil, "user_fields"=>{}},
Prior information: I have very little knowledge in Ruby on Rails and its Gems and Frameworks. So things which seem to be obvious may not be the case to me.
I need to migrate the database from sqlite3 to postgreSQL in our application containing AngularJS in the frontend and Ruby on Rails with ActiveRecord in the backend.
I installed the Ruby Gem pg and changed the database.yml as following:
# This was for sqlite
#adapter: sqlite3
#database: db/gfms.sqlite3
#pool: 5
#timeout: 5000
# This is for postgreSQL
adapter: postgresql
encoding: unicode
database: llqa
pool: 5
username: postgres
password: admin
host: localhost
port: 1234
timeout: 5000
schema_search_path: "gfms"
I'm having several issues now. Some queries return no records where they should, but don't generate an error. But:
A more specific problem I'm having is this error:
E, [2017-04-21T07:34:30.381466 #10961] ERROR -- : PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."configtables" WHERE (parent IS NULL OR parent = "" OR pare...
^
: SELECT COUNT(*) FROM "configtables" WHERE (parent IS NULL OR parent = "" OR parent = 'model')
2017-04-21 07:34:30 - ActiveRecord::StatementInvalid - PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."configtables" WHERE (parent IS NULL OR parent = "" OR pare...
^
: SELECT COUNT(*) FROM "configtables" WHERE (parent IS NULL OR parent = "" OR parent = 'model'):
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `async_exec'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `block in exec_no_cache'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract_adapter.rb:378:in `block in log'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.16/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract_adapter.rb:372:in `log'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `exec_no_cache'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/postgresql_adapter.rb:954:in `select'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/relation/calculations.rb:265:in `execute_simple_calculation'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/relation/calculations.rb:227:in `perform_calculation'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/relation/calculations.rb:119:in `calculate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.16/lib/active_record/relation/calculations.rb:34:in `count'
/Users/ndinatale/leanlogic-qa-prototype/server/lib/models_base.rb:135:in `get_list'
/Users/ndinatale/leanlogic-qa-prototype/server/routes/02_rest_misc.rb:266:in `block in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `block in compile!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `[]'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:994:in `route_eval'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015:in `block in process_route'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `catch'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `process_route'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:973:in `block in route!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `each'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `route!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085:in `block in dispatch!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082:in `dispatch!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `block in call!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `call!'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:225:in `context'
/Library/Ruby/Gems/2.0.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:220:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-1.6.5/lib/rack/nulllogger.rb:9:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-1.6.5/lib/rack/head.rb:13:in `call'
/Library/Ruby/Gems/2.0.0/gems/rack-1.6.5/lib/rack/methodoverride.rb:22:in `call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/show_exceptions.rb:25:in `call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1785:in `synchronize'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1785:in `synchronize'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/configuration.rb:224:in `call'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/server.rb:600:in `handle_request'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/server.rb:435:in `process_client'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/server.rb:299:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `call'
/Library/Ruby/Gems/2.0.0/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
The function where the error happens (the line is commented):
def get_list(limit = nil, page = nil)
coll = all
coll = (block_given?) ? (yield coll) : coll
rowcnt = coll.count # This is the line where the error happens
pages = (limit && limit > 0) ? (rowcnt.to_f/limit).ceil : 1
coll = coll.limit(limit) if limit && limit > 0
coll = coll.offset((page-1)*limit) if limit && limit > 0 && page && page > 1
ret = { rows: coll.all.to_a, rowcnt: rowcnt, page: page || 1, pages: pages, limit: limit || 0 }
def ret.serialize(include = nil)
self[:rows].collect! do |row|
hash = include ? (row.serializable_hash(include: include.incllist)) : row.serializable_hash
(hash['code'] && hash['code'].end_with?('(TR)')) ? nil : ((block_given?) ? yield(hash,row) : hash)
end
self[:rows].compact!
return self.rest_success,true,self
end
return ret
end
This is just an example. My question however is: Is there something in the configuration of ActiveRecord, Ruby or postgreSQL itself so it behaves equally like with sqlite3? What needs to be done, if anything?
I am new to ruby on rails. :(
while doing a search I am getting StockQuote::NoDataForStockError in StocksController#search ...........................
My model
class Stock < ActiveRecord::Base
def self.find_by_ticker(ticker_symbol)
where(ticker: ticker_symbol).first
end
def self.new_from_lookup(ticker_symbol)
looked_up_stock = StockQuote::Stock.quote(ticker_symbol)
return nil unless looked_up_stock.name
new_stock = new(ticker: looked_up_stock, name: looked_up_stock.name)
new_stock.last_price = new_stock.price
new_stock
end
def price
closing_price = StockQuote::Stock.quote(ticker).close
return "#{closing_price} (closing)" if closing_price
opening_price = StockQuote::Stock.quote(ticker).open
return "#{opening_price (opening)}" if opening_price
"Unavailable"
end
end
Errors I am getting in console while doing a search.
StockQuote::NoDataForStockError: StockQuote::NoDataForStockError
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/stock_quote-1.2.3/lib/stock_q
uote/stock.rb:134:in `parse'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/stock_quote-1.2.3/lib/stock_q
uote/stock.rb:86:in `block in quote'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:228:in `call'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:228:in `process_result'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:178:in `block in transmit'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/net/http.rb:853:in `start'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:172:in `transmit'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:64:in `execute'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rest-client-1.6.7/lib/restcli
ent/request.rb:33:in `execute'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/stock_quote-1.2.3/lib/stock_q
uote/stock.rb:84:in `quote'
from C:/Sites/tracker/app/models/stock.rb:19:in `price'
from C:/Sites/tracker/app/models/stock.rb:14:in `new_from_lookup'
from (irb):9
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/co
mmands/console.rb:110:in `start'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/co
mmands/console.rb:9:in `start'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/co
mmands/commands_tasks.rb:68:in `console'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/co
mmands/commands_tasks.rb:39:in `run_command!'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/co
mmands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
If you look at the code for that gem you can see that a StockQuote::NoDataForStockError is returned when the response code is not 200. You'll need to delve into what it doesnt like about the data you are providing. For example you should be able to query the response a bit more and at least determine what url is being sent.
The solution for page interrupting is to use begin rescue blocks every time when we call methods from StockQuote module. In begin part of block use regular call and in rescue part set value to nil and in that case return value 'Unavailable' and similar.begin rescue in Ruby is like try catch in Java. Example:
def price
begin
closing_price = StockQuote::Stock.quote(ticker).close
rescue
closing_price = nil
end
return "#{closing_price} (Closing)" if closing_price
begin
opening_price = StockQuote::Stock.quote(ticker).open
rescue
opening_price = nil
end
return "#{opening_price} (Opening)" if opening_price
'Unavailable'
end