开发者

Ancillary files for view templates in a Rails application

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 adva开发者_如何学运维nce

Miquel


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜