开发者

Loading a file with Rack from a specific route

开发者 https://www.devze.com 2023-01-15 11:03 出处:网络
I\'m following part of this Railscast and trying to load a static file using Rack when a specific route is called:

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.

0

精彩评论

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

关注公众号