Reputation: 6049
I am using quickeebooks gem in my rails 3.2 application. Here I am able to push customer information to the quickbooks successfully.
Now I want to display those records in my rails application for that I have written:
oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, current_login.access_token, current_login.access_secret)
#creating customer in quickbooks
customer_service = Quickeebooks::Online::Service::Customer.new
customer_service.access_token = oauth_client
customer_service.realm_id = current_login.realm_id
customer_service.list
@customer = customer_service.fetch_by_id(12)
and in view:
<%= @customer.name %>
This is working fine. But, I want to display all the customers that I have pushed in the quickbooks. So, I have written:
@customers = customer_service.list
In view :
<%= @customers.inspect %> is inspecting 3 records from quickbooks
But,
<% @customers.each do |customer| %>
<%= customer.name %>
<% end %>
is generating
undefined method `each` for #<Quickeebooks::Collection:0xb5288d8>
How to solve this problem. What am i missing here?
Upvotes: 0
Views: 189
Reputation: 6049
I got it, It was all my mistake. I was about to print array of objects.
But, Like steve have already suggested to use entries
<% @customers.entries.each do |customer| %>
<%= customer.name %>
<% end %>
works for displaying all records
And in Controller :
filters = []
filters << Quickeebooks::Online::Service::Filter.new(:text, :field => 'name', :value => "customer name" )
customer = customer_service.list(filters)
@customer = customer.entries.first
in views
<%= @customer.name %>
for displaying filtered records..
Upvotes: 0
Reputation: 12341
Looking at the "Bringing it all together" section on https://github.com/ruckus/quickeebooks, it appears to me that you'll need to write...
<% @customers.entries.each do |customer| %>
<%= customer.name %>
<% end %>
Upvotes: 1