Reputation: 1923
Not exactly sure where I am doing wrong, I'm following this post on how to set up the Lob gem with Ruby.
Currently my controller is as follows
class UsersController < ApplicationController
require 'lob'
def index
....
end
def create
....
end
def show
@user = User.find(params[:id])
@result = User.return_representative(@user.address)
....
Lob.api_key = 'test_my_api_key'
@lob = Lob.load
@lob.letters.create(
....
)
end
private
....
end
However, I'm getting an error message undefined method `letters'. Am I setting up the call incorrectly, or am I doing something else completely wrong? From the post linked above this does appear to be the way to set up the gem.
Edit: Running @lob.methods
I get the following
[:options, :options=, :areas, :addresses, :bank_accounts, :checks, :countries, :jobs, :objects, :packagings, :postcards, :routes, :services, :settings, :states, :base_url, :construct_url, :format_address_params, :blank?, :present?, :presence, :psych_to_yaml, :to_yaml, :to_yaml_properties, :acts_like?, :duplicable?, :deep_dup, :itself, :try, :try!, :in?, :presence_in, :to_param, :to_query, :instance_values, :instance_variable_names, :to_json_with_active_support_encoder, :to_json_without_active_support_encoder, :to_json, :as_json, :with_options, :html_safe?, :`, :require_or_load, :require_dependency, :load_dependency, :unloadable, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :gem, :class_eval, :silence_warnings, :enable_warnings, :with_warnings, :silence_stderr, :silence_stream, :suppress, :capture, :silence, :quietly, :byebug, :debugger, :concern, :suppress_warnings, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :send, :id]
Seems as if letters is not an available method. Does this mean the documentation is wrong?
Upvotes: 0
Views: 448
Reputation: 7225
Try this out:
Maybe you have used different version of gem, i tried installing this gem and it worked for me.
sachin@sachin-laptop:~$ gem list lob
*** LOCAL GEMS ***
globalid (0.3.6, 0.3.5)
lob (2.4.0)
sachin@sachin-laptop:~$ irb
2.2.2 :001 > require 'lob'
=> true
2.2.2 :002 > Lob.api_key = "test_00001"
=> "test_00001"
2.2.2 :003 > @lob = Lob.load
=> #<Lob::V1::Resource:0x000000034e0a40 @options={:api_host=>"api.lob.com", :protocol=>"https", :api_version=>nil, :api_key=>"test_00001"}>
2.2.2 :004 > @lob.letters
=> #<Lob::V1::Letter:0x0000000342de40 @resource=#<Lob::V1::Resource:0x000000034e0a40 @options={:api_host=>"api.lob.com", :protocol=>"https", :api_version=>nil, :api_key=>"test_00001"}>>
2.2.2 :005 >
Upvotes: 1
Reputation: 2354
Debug after the load to see if the method is actually there:
logger.debug( @lob.methods.sort )
Upvotes: 0