I’ve been using Nick S.'s jruby-rack rails sample for App Engine
Everything has worked well except for a routing issue I’m having,
despite
using a rudimentary routes.rb file:
No route matches “/stylesheets/scaffold.css”
I tried adding the public/stylesheets folder as a resource in
appengine-web.xml.
I also tried to kludge it by making a copy of the public/stylesheets
folder
and putting it under WEB-INF.
Maybe it’s premature to question whether jruby-rack is rewriting the url
correctly but I’m running out of ideas.
My last resort is another kludge - serve static files using a custom
controller in Rails by modifing Nick’s “AssetsController” which reads
files
off the file system and serves them for the app:
class AssetsController < ApplicationController
def show
image_name, image_type = params[:id], params[:format]
filename = PUBLIC_ROOT + “/images/#{image_name}.#{image_type}”
if File.file?(filename)
image_data = File.read filename
response.headers[‘Content-Description’] = “This is
#{image_name}.#{image_type}”
response.headers[‘Last-Modified’] = File.mtime(filename).rfc822
send_data image_data, :type => “image/#{image_type}”, :disposition
=>
‘inline’
else
render :text => “
Not Found
”, :status => :not_found
end
end
end
Tell me there’s a better way!
Hi Charles,
I would try to setup the style sheets as static files.
<static-files>
<include path="/images/**.**" />
<include path="/stylesheets/**.css" />
<include path="/favicon.ico"/>
</static-files>
I had the same problem where I would get a routing error. Setting the
files
to static fixed it for me
Josh
http://www.codingforrent.com
On Tue, Jun 23, 2009 at 5:58 AM, Charles Falconer
<[email protected]
Hi Josh,
Thanks for the suggestion. I tried it out with several variations but
couldn’t get this format to work without a routing error. Afterwards I
looked at your App Engine template and noticed you are using symbolic
links
- could it be that your ‘/stylesheets’ folder is actually in a different
physical location from my ‘war/WEB-INF/public/stylesheets’ folder and
that’s
the reason these files are found in your app and not in mine?
Charles
On Mon, Jun 22, 2009 at 7:13 PM, Charles Falconer
<[email protected]
wrote:
Hi Josh,
Thanks for the suggestion. I tried it out with several variations but
couldn’t get this format to work without a routing error. Afterwards I
looked at your App Engine template and noticed you are using symbolic links
- could it be that your ‘/stylesheets’ folder is actually in a different
physical location from my ‘war/WEB-INF/public/stylesheets’ folder and that’s
the reason these files are found in your app and not in mine?
Charles
Try putting your images and stylesheets in war/stylesheets and
war/images,
etc. GAE won’t serve up any static files from WEB-INF, it’s a protected
directory.
This is the exact reason why warbler takes care of this step for you to
rearrange public files in the root of the war were GAE and other java
application servers expect them.
Cheers,
/Nick
Nick,
That worked. Thanks very much.
There’s only one minor issue now where it reports on the console:
*WARNING: No file found for: /snoop.html
*
when I navigate to
http://localhost:8080/snoop http://localhost:8080/questions
But oddly the snoop view is displayed otherwise without a problem.
Since this warning doesn’t seem to correspond to any problem with the
functioning of the app, I’m not going to worry about it.
Thanks!
Charles