1
votes

In my app I create the following model:

class User
   include Dynamoid::Document
   # fields
   field :user_id, type: Integer
   field :name, type: String
   field :age, type: Integer
end

Then in my route:

# try search
get '/user/:user_name' do
    user = User.where(name: params[:user_name])
    if user
        json success: true, user: user
    else
        json success: false, message: 'User does not exist'
    end
end

But I am getting this: 2016-06-14 16:43:14 - NoMethodError - undefined method 'match' for nil:NilClass:

What I am doing wrong? I want to use ActiveRecords

Adding more details:

/home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:67:in block in partition_matching_region' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:66:ineach' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:66:in find' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:66:inpartition_matching_region' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:55:in get_partition' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:26:inendpoint_for' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:10:in resolve' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/endpoint_provider.rb:80:inresolve' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/aws-sdk-core/plugins/regional_endpoint.rb:24:in block in <class:RegionalEndpoint>' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:64:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:64:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:199:inblock in resolve_defaults' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:57:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:57:ineach' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:198:in resolve_defaults' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:194:invalue_at' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:183:in block in resolve' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/2.1.0/set.rb:263:ineach_key' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/2.1.0/set.rb:263:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:183:inresolve' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:171:in apply_defaults' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/configuration.rb:144:inbuild!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/base.rb:68:in build_config' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/base.rb:19:ininitialize' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.3.7/lib/seahorse/client/base.rb:105:in new' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/adapter_plugin/aws_sdk_v2.rb:15:inconnect!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/adapter.rb:31:in adapter' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/adapter.rb:124:inblock in scan' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/adapter.rb:53:in benchmark' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/adapter.rb:124:inscan' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:142:in block in records_via_scan' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:115:ineach' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:115:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:115:into_a' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:115:in Array' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:115:inrecords' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dynamoid-1.1.0/lib/dynamoid/criteria/chain.rb:95:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:128:into_a' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:128:in as_json' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:159:inblock in as_json' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:159:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:159:inmap' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:159:in as_json' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/json/encoding.rb:35:inencode' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/json/encoding.rb:22:in encode' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.6/lib/active_support/core_ext/object/json.rb:37:into_json_with_active_support_encoder' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/multi_json-1.11.2/lib/multi_json/adapters/json_common.rb:19:in dump' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/multi_json-1.11.2/lib/multi_json/adapter.rb:25:indump' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/multi_json-1.11.2/lib/multi_json.rb:136:in dump' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-contrib-1.4.6/lib/sinatra/json.rb:113:inblock in resolve_encoder_action' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-contrib-1.4.6/lib/sinatra/json.rb:112:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-contrib-1.4.6/lib/sinatra/json.rb:112:inresolve_encoder_action' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-contrib-1.4.6/lib/sinatra/json.rb:98:in json' /home/ll/fx-service/app/routes/users.rb:196:inblock in ' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:inblock in compile!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in []' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:inblock (3 levels) in route!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in route_eval' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:inblock (2 levels) in route!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in block in process_route' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:incatch' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in process_route' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:972:inblock in route!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in each' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:inroute!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1084:in block in dispatch!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:inblock in invoke' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in catch' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:ininvoke' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1081:in dispatch!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:inblock in call!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in block in invoke' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:incatch' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in invoke' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:incall!' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:894:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in context' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/logger.rb:15:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:211:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb:21:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:181:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/tempfile_reaper.rb:15:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lint.rb:49:in_call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lint.rb:37:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/chunked.rb:54:in call' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:incall' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:86:in block in pre_process' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:84:incatch' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:84:in pre_process' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:53:inprocess' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:39:in receive_data' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:inrun_machine' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in run' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:instart' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/thin-1.6.4/lib/thin/server.rb:162:in start' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:inrun' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:286:in start' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:147:instart' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/bin/rackup:4:in <top (required)>' /home/jcastelli/.rbenv/versions/2.1.2/bin/rackup:23:inload' /home/jcastelli/.rbenv/versions/2.1.2/bin/rackup:23:in <top (required)>' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/ruby-debug-ide-0.6.1.beta2/lib/ruby-debug-ide.rb:88:indebug_load' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/ruby-debug-ide-0.6.1.beta2/lib/ruby-debug-ide.rb:88:in debug_program' /home/jcastelli/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/ruby-debug-ide-0.6.1.beta2/bin/rdebug-ide:130:in' -e:1:in load' -e:1:in'

1
Can you show more error trace? - max pleaner
Are you using Sinatra or rails? Your title says one but your code seems to say the other. - Frederick Cheung
You were right! I am using Sinatra - Juan Castelli

1 Answers

1
votes

The error in the stack trace seems to imply the AWS region is nil. Did you configure the Aws library per the documentation here:

https://github.com/Dynamoid/Dynamoid

For example:

Aws.config.update({
    region: 'us-west-2',
    credentials: Aws::Credentials.new('REPLACE_WITH_ACCESS_KEY_ID', 'REPLACE_WITH_SECRET_ACCESS_KEY'),
  })

If so, can you post the code for your Dynamoid.configure call and Aws.config.update calls.