- 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?
|
#
¿
Nov 11, 2007 08:07
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 3, 2024 21:55
|
|
- 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.
|
#
¿
Nov 11, 2007 08:45
|
|