I am trying to load the contents of XML files into a mediumtext field
from a fixture.
heres my fixture so far, with some erb to help me out.
<%
def load_owl(name)
data = File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
data.gsub!("\n", '''')
"!str #{data}"
end
%>
wine:
name: Wine
body: <%= load_owl(:wine) %>
teams:
name: Teams
body: <%= load_owl(:teams) %>
pizza:
name: Pizza
body: <%= load_owl(:pizza) %>
------------------------
This worked for Wine and Teams, but pizza has screwed the pooch. All I
get is YAML parse errors, which are very hard to pinpoint.
So if anyone has a better idea about how to do a basic YAML escape on a
something 4000 lines of XML, that would be very useful. Any ideas?
--
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-/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
-~----------~----~----~----~------~----~------~--~---
Well, I never solved this, but came up with a workaround. Since I
don''t
need these fixtures to have any association linkage I just added a
method to my spec helper:
def get_owl(name)
returning Owl.find_or_initialize_by_name(name) do |owl|
if owl.new_record?
owl.name = name
owl.body =
File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
owl.save
end
end
end
Seems to work well enough for my needs.
Alex Wayne wrote:> I am trying to load the contents of XML files into a mediumtext field
> from a fixture.
>
> heres my fixture so far, with some erb to help me out.
>
> <%
> def load_owl(name)
> data =
File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
> data.gsub!("\n", '''')
> "!str #{data}"
> end
> %>
>
> wine:
> name: Wine
> body: <%= load_owl(:wine) %>
>
> teams:
> name: Teams
> body: <%= load_owl(:teams) %>
>
> pizza:
> name: Pizza
> body: <%= load_owl(:pizza) %>
--
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-/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
-~----------~----~----~----~------~----~------~--~---