Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
copla
Jun 12, 2005
Everything will fall, fall right into place
I'm trying to style my XML with XSL and then spit it out as html using REXML and Ruby-XSLT... problem being, I can't seem to open up my files.

This is my model:
code:
  def self.find_blog_posts

    require "net/http"
    require "net/https"
    require "rubygems"
    require "rexml/document"
    require "xml/xslt"
    include REXML
    
    doc = XML::XSLT.new()
    doc.xml = REXML::Document.new File.new("/blog.xml")
    doc.xsl = REXML::Document.new File.new("/blox.xsl")
    @slider_content = xslt.serve() 
  end    
The error I get is:

code:
>> Home.find_blog_posts
Errno::ENOENT: No such file or directory - /blog.xml
	from /Users/copla/project/app/models/home.rb:52:in `initialize'
	from /Users/copla/project/app/models/home.rb:52:in `new'
	from /Users/copla/project/app/models/home.rb:52:in `find_blog_posts'
	from (irb):1
I haven't had any issue opening and calling files from my stylesheets and my view files, from view I just do "/images/file.jpg" to call an image in public/images, but I can't do the same from model- when I do "/blog.xml" for it being in public/blog.xml, it doesn't work. When I do "/stylesheets/blog.xml", it doesn't work (for that I try moving the file to stylesheets of course, it's currently moved back to public). It also opens properly when I open it directly in my browser, so it's clear that I'm using the wrong syntax.

How exactly are you supposed to open a file in public from model?

Adbot
ADBOT LOVES YOU

copla
Jun 12, 2005
Everything will fall, fall right into place

Argue posted:

You don't want to do that. Not in the model, at least. The entire point of splitting your code into model, view, and controller is to keep your logic separate from your presentation. The public folder is for the web layer, so if you open files from public in your model, that means that when you modify the presentation layer, you'll have to worry about not accidentally screwing up the internals of the application.
I guess I should have explained the purpose of the XML files first- right now I'm trying to test that Ruby-XSLT will transform the XML right when I have a file locally, because I was having a hell of a time pulling down a remote XML file. What I want to do, ideally, is pull down the XML from the server (I'm getting blog posts from the Tumblr API, which you get with an HTTP request, and then get back the XML. I then need format it with the XSLT- so what I'm trying to do now is just get local XML working and formatting right.

Then I can work on pulling down the XML and somehow saving it, as it comes in as pure text, so it would need to have a declaration added at the beginning, then I can transform that, in turn, with the XSL. And THEN I can hopefully get it so that all of it happens serverside, updated hourly, and cached.

But... now I need to open up the local file so I can test the first step.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply