HazemS24
HazemS24

Reputation: 3

How do I render an easypost address by id from a user?

I am trying to find the address by the "address_id" column in the user model to then render that address.

Note: Since this is easypost I did not make the address model itself and there is no association between the user model and the address object.

my _user.json.jbuilder file:

json.extract! user, :id, :username, :created_at, :updated_at, :deleted_at, :is_disabled

json.address EasyPost::Address.retrieve(user.address_id), partial: 'addresses/address', as: :address

I was expecting the above code to find the address and go to _address.json.jbuilder to render it as part of the user:

json.extract! address, :street1, :street2, :city, :state, :zip, :country, :residential

error that I am getting:

"ActionView::Template::Error: The requested resource could not be found."

Upvotes: 0

Views: 65

Answers (1)

Logan Simonsen
Logan Simonsen

Reputation: 89

This error "The requested resource could not be found." is any EasyPost API error which could indicate the following possibilities:

  1. your API key is typoed or truncated when making the request (not likely if other requests are working ok.)
  2. You are attempting to access an address object in the wrong mode. For example if I create an address, let's say "adr_X", that was created in the EasyPost TEST environment, and then I try to retrieve that address object using my EasyPost PRODUCTION API key, I will get this error because "adr_X" is not found within the PRODUCTION environment. (this is the most likely reason you are getting this error IMO)
  3. similar to #2, your address object id is typoed, or truncated, or the variable isn't assigned a value yet and therefore EasyPost cannot find it in the environment.

Upvotes: 0

Related Questions