Hi, I am trying to get the response in xml format. For that I have written following code def user_details @user=User.find(params[:id]) @company=@user.company respond_to do |format| format.xml {render :xml=> @user.to_xml(:include => @company)} end end I am getting following error:- "undefined method `macro'' for nil:NilClass" Can anyone tell, what is wrong with the code? Thanks, Mike -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 9, 11:15 am, Mike Disuza <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I am trying to get the response in xml format. > For that I have written following code > > def user_details > @user=User.find(params[:id]) > @compa...-ASQrhD/3864ki8xbSfFMpQ@public.gmane.org > respond_to do |format| > format.xml {render :xml=> @user.to_xml(:include => @company)}you should be giving the name of the association - not the actual associated object Fred> end > end > > I am getting following error:- > "undefined method `macro'' for nil:NilClass" > > Can anyone tell, what is wrong with the code? > > Thanks, > Mike > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, How can I create user defined xml structure? My previous code gives me xml like: <user> <name>Mike></name> <email>mike-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> <company> <id>2</id> <name>ABC</name> </company> </user> I need to create a XML like this:- <user> <name>Mike</name> <email>mke-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> <company_id>2</company_id> </user> Any help appreciated. Thanks, Mike -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 9, 12:00 pm, Mike Disuza <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Fred, > How can I create user defined xml structure? > > My previous code gives me xml like: > <user> > <name>Mike></name> > <email>m...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> > <company> > <id>2</id> > <name>ABC</name> > </company> > </user> > > I need to create a XML like this:- > > <user> > <name>Mike</name> > <email>m...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> > <company_id>2</company_id> > </user>If the default to_xml isn''t giving you want you want you can override it yourself (to_xml does take quite a few options though - have a play with them) Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello, if you remove the :include => :company only the company_id will be serialized. The following code should work as you expect : render :xml => @user Mickael On 9 August 2010 13:00, Mike Disuza <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Fred, > How can I create user defined xml structure? > > My previous code gives me xml like: > <user> > <name>Mike></name> > <email>mike-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> > <company> > <id>2</id> > <name>ABC</name> > </company> > </user> > > I need to create a XML like this:- > > <user> > <name>Mike</name> > <email>mke-/E1597aS9LQAvxtiuMwx3w@public.gmane.org</email> > <company_id>2</company_id> > </user> > > > Any help appreciated. > > Thanks, > Mike > -- > 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, I need the "company_id" in the XML. render :xml=> @user will only include the user attributes. Thanks, Mike -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 9, 2:16 pm, Mike Disuza <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I need the "company_id" in the XML. > > render :xml=> @user will only include the user attributes. >Is the assocation user has_one company ? If so (ie user has no company_id attribute) then the easiest thing is probably to write a method on user that returns the appropriate id and then use the :methods option to to_xml to include that in the output Fred> Thanks, > Mike > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.