2017-03-23 2 views
0

Railsに表示したいShopifyオブジェクトを受け取りました。私のHTMLでインスタンス変数をHTMLで表示する方法

私はこのコードを持っている:

[#<ShopifyAPI::Order:0x007f90f53117c0 @attributes={"id"=>4889340686, "email"=>"", "closed_at"=>nil, "created_at"=>"2017-03-21T20:09:41-04:00", "updated_at"=>"2017-03-21T20:09:41-04:00", "number"=>3, "note"=>"", "token"=>"74b8cae748de2154dae08edc4cb9b0b8", "gateway"=>"manual", "test"=>false, "total_price"=>"121.00", "subtotal_price"=>"110.00", "total_weight"=>0, "total_tax"=>"11.00", "taxes_included"=>false, "currency"=>"AUD", "financial_status"=>"paid", "confirmed"=>true, "total_discounts"=>"0.00", "total_line_items_price"=>"110.00", "cart_token"=>nil, "buyer_accepts_marketing"=>false, "name"=>"#1003", "referring_site"=>nil, "landing_site"=>nil, "cancelled_at"=>nil, "cancel_reason"=>nil, "total_price_usd"=>"93.51", "checkout_token"=>nil, "reference"=>nil, "user_id"=>107636622, "location_id"=>40480334, "source_identifier"=>nil, "source_url"=>nil, "processed_at"=>"2017-03-21T20:09:41-04:00", "device_id"=>nil, "browser_ip"=>nil, "landing_site_ref"=>nil, "order_number"=>1003, "discount_codes"=>[], "note_attributes"=>[], "payment_gateway_names"=>["manual"], "processing_method"=>"manual", "checkout_id"=>nil, "source_name"=>"shopify_draft_order", "fulfillment_status"=>nil, "tax_lines"=>[#<ShopifyAPI::TaxLine:0x007f90f9e49ee0 @attributes={"title"=>"GST", "price"=>"11.00", "rate"=>0.1}, @prefix_options={}, @persisted=true>], "tags"=>"", "contact_email"=>nil, "order_status_url"=>nil, "line_items"=>[#<ShopifyAPI::LineItem:0x007f90f9e492b0 @attributes={"id"=>9182800654, "variant_id"=>37496676110, "title"=>"Expensive Product", "quantity"=>1, "price"=>"100.00", "grams"=>0, "sku"=>"", "variant_title"=>nil, "vendor"=>"Gronade Dev Test", "fulfillment_service"=>"manual", "product_id"=>10105372366, "requires_shipping"=>true, "taxable"=>true, "gift_card"=>false, "name"=>"Expensive Product", "variant_inventory_management"=>nil, "properties"=>[], "product_exists"=>true, "fulfillable_quantity"=>1, "total_discount"=>"0.00", "fulfillment_status"=>nil, "tax_lines"=>[#<ShopifyAPI::TaxLine:0x007f90f3933650 @attributes={"title"=>"GST", "price"=>"10.00", "rate"=>0.1}, @prefix_options={}, @persisted=true>]}, @prefix_options={}, @persisted=true>, #<ShopifyAPI::LineItem:0x007f90f3932cf0 @attributes={"id"=>9182800718, "variant_id"=>37496692110, "title"=>"Cheap Product", "quantity"=>1, "price"=>"10.00", "grams"=>0, "sku"=>"", "variant_title"=>nil, "vendor"=>"Gronade Dev Test", "fulfillment_service"=>"manual", "product_id"=>10105380174, "requires_shipping"=>true, "taxable"=>true, "gift_card"=>false, "name"=>"Cheap Product", "variant_inventory_management"=>nil, "properties"=>[], "product_exists"=>true, "fulfillable_quantity"=>1, "total_discount"=>"0.00", "fulfillment_status"=>nil, "tax_lines"=>[#<ShopifyAPI::TaxLine:0x007f90f9e53be8 @attributes={"title"=>"GST", "price"=>"1.00", "rate"=>0.1}, @prefix_options={}, @persisted=true>]}, @prefix_options={}, @persisted=true>], "shipping_lines"=>[], "fulfillments"=>[], "refunds"=>[], "customer"=>#<ShopifyAPI::Customer:0x007f90f9e53238 @attributes={"id"=>5793410830, "email"=>nil, "accepts_marketing"=>false, "created_at"=>"2017-03-21T20:09:21-04:00", "updated_at"=>"2017-03-21T20:09:41-04:00", "first_name"=>"Benderditch", "last_name"=>"Cucumberpatch", "orders_count"=>1, "state"=>"disabled", "total_spent"=>"121.00", "last_order_id"=>4889340686, "note"=>nil, "verified_email"=>false, "multipass_identifier"=>nil, "tax_exempt"=>false, "phone"=>nil, "tags"=>"", "last_order_name"=>"#1003"}, @prefix_options={}, @persisted=true>}, @prefix_options={}, @persisted=true>] 

どのように私はこの出力を構築、または私はこれらの変数にアクセスしない方法をよりよくすることができます

<ul> 
    <% @customers.each do |customer| %> 
    <li><%= customer.orders %></li> 
    <% end %> 
</ul> 

を私は、この出力を取得しますか?私は@注釈付きのインスタンス変数で何をすべきかわかりません。

私はこのようなものを出力してみてください。

<ul> 
    <% @customers.each do |customer| %> 
    <li><%= customer.orders.attributes %></li> 
    <% end %> 
</ul> 

が、私はエラーを取得します。 customers.orders以来

+1

'customer.orders'が配列でありますあなたは '@ customers'の配列のようにループする必要があります – Iceman

+0

なぜdownvotedを取得しますか?thanks Iceman – Saibottrenham

+0

上向き/下向きの矢印上にマウスを置くと、下向きの投票が説明されます。ドキュメンテーションとチュートリアルと下の票は、研究を示さない質問のためのものです。ドキュメントを読んで答えが見つからない場合は、wheあなたは検索し、そのページがなぜ役に立たなかったのか説明します。 –

答えて

2

は、(それが実際にActiveRecord::Associations::CollectionProxyだ、あなたはそれをループにあなたがcustomersに掛け同じように持っている一種の辞書です。このように:。

<ul> 
    <% @customers.each do |customer| %> 
    <% customer.orders.each do |order| %> 
     <li><%= order.whatever_field_you_want %></li> 
    <% end %> 
    <% end %> 
</ul> 
+0

ありがとう、それは非常に良い説明です:) – Saibottrenham

+0

素晴らしい!それがあなたを助けてくれたら、私の答えを受け入れるか、投票してもらえませんか:)ありがとう! – Mark

関連する問題