cremes.devlist-ee4meeAH724@public.gmane.org
2006-Nov-18 23:35 UTC
dynamic fixture reading in a file
I have a text field in a database that I would like to populate with some data. In my fixture yaml file I''m trying to read in the file as an entry, but rails barfs on it. Here''s what it looks like: one: id: 1 manifest: <%= File.read(''MANIFEST'').to_yaml %> The ''MANIFEST'' file is a plist (a type of xml). The AR::read_fixtures method barfs and complains that the yaml file requires a specific kind of format. Anyone know how to correctly read in a file inside a fixture to populate a text field? Thanks cr --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
cremes.devlist-ee4meeAH724@public.gmane.org
2006-Nov-19 00:20 UTC
Re: dynamic fixture reading in a file
On Nov 18, 2006, at 5:35 PM, cremes.devlist-ee4meeAH724@public.gmane.org wrote:> > I have a text field in a database that I would like to populate with > some data. In my fixture yaml file I''m trying to read in the file as > an entry, but rails barfs on it. > > Here''s what it looks like: > > one: > id: 1 > manifest: <%= File.read(''MANIFEST'').to_yaml %> > > The ''MANIFEST'' file is a plist (a type of xml). The AR::read_fixtures > method barfs and complains that the yaml file requires a specific > kind of format.I see the problem a little more clearly now. When I read in the file, it has linefeeds and carriage returns in it which are preserved even when converting to yaml. Apparently the yaml file requires all multiline records to be indented the same way. Luckily I do not need to preserve tabs, line feeds or carriage returns, so I rewrote the line to strip those out. This has the effect of keeping the file all on a single line in the yaml file, so it doesn''t choke. one: id: 1 manifest: <%= File.read(''MANIFEST'').gsub!(/[\t\n]/,'''') %> Anyone know how to do this in the event that I *do* need to preserve line feeds and carriage returns? cr --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---