Hey, Guys! I have next action in controller products: def who_bought @product = Product.find(params[:id] ) respond_to do |format| format.html format.xml { render :xml => @product.to_xml( :include => :order ) } format.json {render :json => @product.to_json(:include => :order ) } end end routes.rb ....................... resources :products do get :who_bought member: :on end .......................... I want check, how work in xml format. How me call in command line my format xml? (format.xml { render :xml => @product.to_xml( :include => :order ) }) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Mar 31, 2013 at 5:17 AM, Dmitrij B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > I want check, how work in xml format. How me call in command line my > format xml? (format.xml { render :xml => @product.to_xml( :include => > :order ) }) >I guess you want to see what''s the output in rails console Just open it and then do Product.find(SOME_ID).to_xml then you''ll get the info -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
For example i can see in command line: curl --silent http://localhost:3000/products/3/who_bought.atom.builder. And how me call in command line format.xml? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
pass accept header in curl: -H "Accept: application/xml" 2013/3/31 Dmitrij B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> For example i can see in command line: curl --silent > http://localhost:3000/products/3/who_bought.atom.builder. > > And how me call in command line format.xml? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Pagarbiai, Gintautas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
i add curl --silent http://localhost:3000/products/3/who_bought -H "Accept: application/xml" show error: <h1> NoMethodError in ProductsController#who_bought </h1> <pre>undefined method `order' for #<Product:0xb6196084></pre> <p><code>Rails.root: /home/dima/RubyOnRails/Projects/depot</code></p> its my product.rb: class Product < ActiveRecord::Base has_many :line_items, dependent: :destroy has_many :orders, through: :line_items before_destroy :ensure_not_referenced_by_any_line_item attr_accessible :title, :description, :image_url, :price validates :title, :description, :image_url, :price, :presence => true validates :price, numericality: {greater_than_or_equal_to: 0.01} validates :title, uniqueness: true # validates :image_url, allow_blank: true, format: { # with: %r{ \.(gif|jpg|png)$}i, # message: ''gif, jpg png. '' #} #validates :image_url, :uniqueness => false def ensure_not_referenced_by_any_line_item if line_items.empty? return true else errors.add(:base, " have products line") return false end end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Mar 31, 2013 at 1:55 PM, Dmitrij B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i add curl --silent http://localhost:3000/products/3/who_bought -H > "Accept: application/xml" >According to that url you''re going to action "who_bought" on "products_controller" and the problem is inside that action <pre>undefined method `order' for #<Product:0xb6196084></pre> It seems you are doing Product.order, but your model says that you have a has_many relation with orders so it should be Product.orders (maybe I''m wrong I''m not sure what''s inside your "who_bought" action) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Sorry, I haven''t seen the action that you post in the beginning def who_bought @product = Product.find(params[:id] ) respond_to do |format| format.html format.xml { render :xml => @product.to_xml( :include => :order ) } format.json {render :json => @product.to_json(:include => :order ) } end end It should be @product.to_xml(:include => :orders) Note the plural -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
yea) I just do not notice. Thanks for your help! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.