Loading a file with Rack from a specific route
I'm following part of this Railscast and trying to load a static file using Rack when a specific route is called:
match "/myApi.js" => lambda { |env| [200, {}, Rack::File.new("/v1/myApi.js")] }
开发者_Python百科
No matter what I do, even if I just try to send a string through:
match "/myApi.js" => lambda { |env| [200, {}, "Hello World"] }
I still receive:
NoMethodError
undefined method `body' for #<Rack::File:0x00000101edcea0 @root="/my/path">
How can I render a static file using rack?
Try putting that file in your <rails-root>/public/
directory. By default, a Rails app will serve any file in that directory. EG with a new Rails app, you can go to http://localhost:3000/index.html
and it will serve up public/index.html
. Put your api.js file in there, and you can do the same.
精彩评论