In my controller I have an instance of a custom report class, the instance responds to to_csv, which returns a csv string. I was hoping to be able to use respond_with, in the same way I would if I wanted a json representation of this object. Instead I see an error because Rails is expecting there to be a template. ActionView::MissingTemplate (Missing template admin/reports/trips with {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} in view paths Is this the correct behaviour, I had a brief look through the rails responder code and it looked to me like it should first try and render a template, then if it can''t find one try calling to_#{format}. A sample of my code is in this gist https://gist.github.com/854903 -- 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.
All right, but, before, why would you do that? I think if you really need to use csv (eg. some legacy system), you would rather want to read from the csv file, turn it into object and serialize it with JSON. In the other end you''d do the opposit. I don''t think csv is a good format to respond with, just a persistency format, very limited by the way. On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In my controller I have an instance of a custom report class, the > instance responds to to_csv, which returns a csv string. I was hoping > to be able to use respond_with, in the same way I would if I wanted a > json representation of this object. Instead I see an error because > Rails is expecting there to be a template. > > ActionView::MissingTemplate (Missing template admin/reports/trips with > {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > in view paths > > Is this the correct behaviour, I had a brief look through the rails > responder code and it looked to me like it should first try and render > a template, then if it can''t find one try calling to_#{format}. > > A sample of my code is in this gisthttps://gist.github.com/854903-- 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.
I''d like to strongly disagree. While csv is not a great way to send objects back and forth, it is a fantastic way to give reports to users, since they can play around with them in Excel. On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> All right, but, before, why would you do that? I think if you really > need to use csv (eg. some legacy system), you would rather want to > read from the csv file, turn it into object and serialize it with > JSON. In the other end you''d do the opposit. I don''t think csv is a > good format to respond with, just a persistency format, very limited > by the way. > > On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > In my controller I have an instance of a custom report class, the > > instance responds to to_csv, which returns a csv string. I was hoping > > to be able to use respond_with, in the same way I would if I wanted a > > json representation of this object. Instead I see an error because > > Rails is expecting there to be a template. > > > ActionView::MissingTemplate (Missing template admin/reports/trips with > > {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > > in view paths > > > Is this the correct behaviour, I had a brief look through the rails > > responder code and it looked to me like it should first try and render > > a template, then if it can''t find one try calling to_#{format}. > > > A sample of my code is in this gisthttps://gist.github.com/854903-- 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.
Adam, Humm... got your point, you''r right. On Mar 6, 10:18 am, Adam Solove <asol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to strongly disagree. While csv is not a great way to send > objects back and forth, it is a fantastic way to give reports to > users, since they can play around with them in Excel. > > On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > All right, but, before, why would you do that? I think if you really > > need to use csv (eg. some legacy system), you would rather want to > > read from the csv file, turn it into object and serialize it with > > JSON. In the other end you''d do the opposit. I don''t think csv is a > > good format to respond with, just a persistency format, very limited > > by the way. > > > On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > In my controller I have an instance of a custom report class, the > > > instance responds to to_csv, which returns a csv string. I was hoping > > > to be able to use respond_with, in the same way I would if I wanted a > > > json representation of this object. Instead I see an error because > > > Rails is expecting there to be a template. > > > > ActionView::MissingTemplate (Missing template admin/reports/trips with > > > {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > > > in view paths > > > > Is this the correct behaviour, I had a brief look through the rails > > > responder code and it looked to me like it should first try and render > > > a template, then if it can''t find one try calling to_#{format}. > > > > A sample of my code is in this gisthttps://gist.github.com/854903-- 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.
On Sun, Mar 6, 2011 at 7:18 AM, Adam Solove <asolove-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to strongly disagree. While csv is not a great way to send > objects back and forth, it is a fantastic way to give reports to > users, since they can play around with them in Excel. >On the other hand, if you know that the users who are going to be viewing the report in Excel are using Office 2007 or greater you can just format the data into an Excel .xlsx file and present them that as the result. No need to worry about converting to .csv and then the user having to import it into Excel to read it. B. -- 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.
I agree with you, though I find it amusing when people export things to csv just to run totals. So, it''s important to work out just why they want it in csv Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 07/03/2011, at 12:18 AM, Adam Solove <asolove-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to strongly disagree. While csv is not a great way to send > objects back and forth, it is a fantastic way to give reports to > users, since they can play around with them in Excel. > > On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> All right, but, before, why would you do that? I think if you really >> need to use csv (eg. some legacy system), you would rather want to >> read from the csv file, turn it into object and serialize it with >> JSON. In the other end you''d do the opposit. I don''t think csv is a >> good format to respond with, just a persistency format, very limited >> by the way. >> >> On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >> >>> In my controller I have an instance of a custom report class, the >>> instance responds to to_csv, which returns a csv string. I was hoping >>> to be able to use respond_with, in the same way I would if I wanted a >>> json representation of this object. Instead I see an error because >>> Rails is expecting there to be a template. >> >>> ActionView::MissingTemplate (Missing template admin/reports/trips with >>> {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} >>> in view paths >> >>> Is this the correct behaviour, I had a brief look through the rails >>> responder code and it looked to me like it should first try and render >>> a template, then if it can''t find one try calling to_#{format}. >> >>> A sample of my code is in this gisthttps://gist.github.com/854903 > > -- > 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. >-- 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.
I appreciate the discussion on the pros and cons of exporting to csv, however my question was more to do with what the expected behaviour of respond_with is when the request format is csv. I would have thought that since the object I am passing to respond_with has a to_csv method that it wouldn''t also need a template to return a response, much like a json, xml or yaml request. Is this not the expected behaviour? Maybe a bug in rails, or just something that could do with some more documentation? From ActionController::Responder # When a request comes in, for example for an XML response, three steps happen: # # 1) the responder searches for a template at people/index.xml; # # 2) if the template is not available, it will invoke <code>#to_xml</code> on the given resource; # # 3) if the responder does not <code>respond_to :to_xml</code>, call <code>#to_format</code> on it. On Mar 7, 1:43 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> I agree with you, though I find it amusing when people export things to csv just to run totals. So, it''s important to work out just why they want it in csv > > Blog:http://random8.zenunit.com/ > Twitter:http://twitter.com/random8r > Learn:http://sensei.zenunit.com/ > New video up now athttp://sensei.zenunit.com/real fastcgi rails deploy process! Check it out now! > > On 07/03/2011, at 12:18 AM, Adam Solove <asol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I''d like to strongly disagree. While csv is not a great way to send > > objects back and forth, it is a fantastic way to give reports to > > users, since they can play around with them in Excel. > > > On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> All right, but, before, why would you do that? I think if you really > >> need to use csv (eg. some legacy system), you would rather want to > >> read from the csv file, turn it into object and serialize it with > >> JSON. In the other end you''d do the opposit. I don''t think csv is a > >> good format to respond with, just a persistency format, very limited > >> by the way. > > >> On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> In my controller I have an instance of a custom report class, the > >>> instance responds to to_csv, which returns a csv string. I was hoping > >>> to be able to use respond_with, in the same way I would if I wanted a > >>> json representation of this object. Instead I see an error because > >>> Rails is expecting there to be a template. > > >>> ActionView::MissingTemplate (Missing template admin/reports/trips with > >>> {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > >>> in view paths > > >>> Is this the correct behaviour, I had a brief look through the rails > >>> responder code and it looked to me like it should first try and render > >>> a template, then if it can''t find one try calling to_#{format}. > > >>> A sample of my code is in this gisthttps://gist.github.com/854903 > > > -- > > 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 athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Did you have any luck with this, Oliver? I''ve encountered exactly the same problem. Should we reported this as a bug? On Mar 7, 12:08 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I appreciate the discussion on the pros and cons of exporting to csv, > however my question was more to do with what the expected behaviour of > respond_with is when the request format is csv. > > I would have thought that since the object I am passing to > respond_with has a to_csv method that it wouldn''t also need a template > to return a response, much like a json, xml or yaml request. Is this > not the expected behaviour? Maybe a bug in rails, or just something > that could do with some more documentation? > > From ActionController::Responder > > # When a request comes in, for example for an XML response, three > steps happen: > # > # 1) the responder searches for a template at people/index.xml; > # > # 2) if the template is not available, it will invoke > <code>#to_xml</code> on the given resource; > # > # 3) if the responder does not <code>respond_to :to_xml</code>, > call <code>#to_format</code> on it. > > On Mar 7, 1:43 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > > > > I agree with you, though I find it amusing when people export things to csv just to run totals. So, it''s important to work out just why they want it in csv > > > Blog:http://random8.zenunit.com/ > > Twitter:http://twitter.com/random8r > > Learn:http://sensei.zenunit.com/ > > New video up now athttp://sensei.zenunit.com/realfastcgi rails deploy process! Check it out now! > > > On 07/03/2011, at 12:18 AM, Adam Solove <asol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''d like to strongly disagree. While csv is not a great way to send > > > objects back and forth, it is a fantastic way to give reports to > > > users, since they can play around with them in Excel. > > > > On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> All right, but, before, why would you do that? I think if you really > > >> need to use csv (eg. some legacy system), you would rather want to > > >> read from the csv file, turn it into object and serialize it with > > >> JSON. In the other end you''d do the opposit. I don''t think csv is a > > >> good format to respond with, just a persistency format, very limited > > >> by the way. > > > >> On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>> In my controller I have an instance of a custom report class, the > > >>> instance responds to to_csv, which returns a csv string. I was hoping > > >>> to be able to use respond_with, in the same way I would if I wanted a > > >>> json representation of this object. Instead I see an error because > > >>> Rails is expecting there to be a template. > > > >>> ActionView::MissingTemplate (Missing template admin/reports/trips with > > >>> {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > > >>> in view paths > > > >>> Is this the correct behaviour, I had a brief look through the rails > > >>> responder code and it looked to me like it should first try and render > > >>> a template, then if it can''t find one try calling to_#{format}. > > > >>> A sample of my code is in this gisthttps://gist.github.com/854903 > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ve looked into this and it seems that there is no mechanism in AC that would call to_csv automatically. The code in action_controller/ metal/renderers.rb suggests that xml and json are just two special cases that do that. On Mar 31, 3:01 pm, mfilej <miha.fi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Did you have any luck with this, Oliver? > > I''ve encountered exactly the same problem. Should we reported this as > a bug? > > On Mar 7, 12:08 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I appreciate the discussion on the pros and cons of exporting to csv, > > however my question was more to do with what the expected behaviour of > > respond_with is when the request format is csv. > > > I would have thought that since the object I am passing to > > respond_with has a to_csv method that it wouldn''t also need a template > > to return a response, much like a json, xml or yaml request. Is this > > not the expected behaviour? Maybe a bug in rails, or just something > > that could do with some more documentation? > > > From ActionController::Responder > > > # When a request comes in, for example for an XML response, three > > steps happen: > > # > > # 1) the responder searches for a template at people/index.xml; > > # > > # 2) if the template is not available, it will invoke > > <code>#to_xml</code> on the given resource; > > # > > # 3) if the responder does not <code>respond_to :to_xml</code>, > > call <code>#to_format</code> on it. > > > On Mar 7, 1:43 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > > > I agree with you, though I find it amusing when people export things to csv just to run totals. So, it''s important to work out just why they want it in csv > > > > Blog:http://random8.zenunit.com/ > > > Twitter:http://twitter.com/random8r > > > Learn:http://sensei.zenunit.com/ > > > New video up now athttp://sensei.zenunit.com/realfastcgirails deploy process! Check it out now! > > > > On 07/03/2011, at 12:18 AM, Adam Solove <asol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''d like to strongly disagree. While csv is not a great way to send > > > > objects back and forth, it is a fantastic way to give reports to > > > > users, since they can play around with them in Excel. > > > > > On Mar 5, 9:03 am, marco <marcofog...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >> All right, but, before, why would you do that? I think if you really > > > >> need to use csv (eg. some legacy system), you would rather want to > > > >> read from the csv file, turn it into object and serialize it with > > > >> JSON. In the other end you''d do the opposit. I don''t think csv is a > > > >> good format to respond with, just a persistency format, very limited > > > >> by the way. > > > > >> On Mar 4, 1:22 pm, olivernn <oliver.nightinga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > >>> In my controller I have an instance of a custom report class, the > > > >>> instance responds to to_csv, which returns a csv string. I was hoping > > > >>> to be able to use respond_with, in the same way I would if I wanted a > > > >>> json representation of this object. Instead I see an error because > > > >>> Rails is expecting there to be a template. > > > > >>> ActionView::MissingTemplate (Missing template admin/reports/trips with > > > >>> {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} > > > >>> in view paths > > > > >>> Is this the correct behaviour, I had a brief look through the rails > > > >>> responder code and it looked to me like it should first try and render > > > >>> a template, then if it can''t find one try calling to_#{format}. > > > > >>> A sample of my code is in this gisthttps://gist.github.com/854903 > > > > > -- > > > > 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@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > For more options, visit this group athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.