views:

12

answers:

1

Dear colleagues,

A very basic question on Rails. I would like to create a Rails application that, besides the "regular" html view, it can generate a set of XML files. I am aware that I can tailor the templating using the "respond_to" command and using ERB with the templates ???.xml.erb. My question is: suppose that the final document consists in several of these XML files (some are template and must be autoedited by the application but some others are "static" and do not need to be changed). In this scenario, which would be the best location in the application folder to put these ancillary files of the templates?

Thanks a lot in advance

Miquel

A: 

I hope I'm understanding your question...

If your responses are most static you should continue using the .xml.erb templates, but if you need something more dynamic maybe you could consider builder templates, which have a .builder or .rxml extension.

This is an example of what a builder template might look like:

xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
  xml.channel do
    xml.title(@feed_title)
    xml.link(@url)
    xml.description "Basecamp: Recent items"
    xml.language "en-us"
    xml.ttl "40"

    for item in @recent_items
      xml.item do
        xml.title(item_title(item))
        xml.description(item_description(item)) if item_description(item)
        xml.pubDate(item_pubDate(item))
        xml.guid(@person.firm.account.url + @recent_items.url(item))
        xml.link(@person.firm.account.url + @recent_items.url(item))

        xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
      end
    end
  end
end
jonnii
That is a good hint indeed (I am a newbie in Rails). Thanks a lot!My question was more on the line of: how do I organize, in the rails directory application, the set of xml files (i.e. full template containing both the xml files that are "static" and the ones that have to be dynamically changed)? Is it best to put it in the views directory? Should I generate a new directory in the rails application? Thanks a lot
Tryskele
You should put them in the `/views/` directory.
jonnii