Tag: 机架

为什么Rails测试环境中的机架env哈希是空的?

在我的Rails应用程序中,我正在访问我的一个控制器操作中的env哈希。 有点像: def my_before_filter env[‘some.key’] = “Something or other” end 这对我的要求非常有用。 如果我在测试环境中启动我的Rails应用程序,并访问如下操作: # /users in UsersController#index def index puts env.inspect end 然后,env哈希的内容按预期输出到控制台。 当我从RSPec示例中获取此操作时,输出是空哈希? it ‘should get the index action’ do get :index end …..{}…. # rspec output 为什么env哈希是空的? 我已经构建了一个虚拟轨道应用来展示这一点

机架:管理客户端和服务应用程序响应

我正在使用Ruby on Rails 3,我在服务应用程序上正确设置Rack中间件行为时遇到了一些问题,以便使用来自客户端应用程序的传入请求。 我改变了我的代码 第一个代码 # application.rb config.middleware.use “Rack::Api::User” # lib/rack/api/user.rb module Rack module Api class User def initialize(app) # Changed part @app = app end def call(env) # Changed line if env[“PATH_HOST”] =~ /^\/api\/user\//i # Changed line @app.call(env) # Changed line else [200, {}, [“Nope, missed it. Here’s env:\n” + env.inspect]] end end […]

从模型中使用路径助手时,RackEnv不受尊重

在Passenger for Apache上运行Rails 3.2.13。 我的vhost: ServerName server DocumentRoot /srv/http Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all RackEnv test RackBaseURI /rails_app Options -MultiViews 效果很好。 唯一的问题是我在模型中使用路由url助手,如下所示: # egg.rb def to_exhibit return { :edit_path => Rails.application.routes.url_helpers.edit_egg_path(self) } end 在视图中呈现URL时,子URI将按照我的预期使用,但是当从模型中访问URL帮助程序时,它将被丢弃,路径始终相对于根。 来自eggs_controller.rb: edit_egg_path(1000) –> /rails_app/eggs/1000/edit 来自some_model.rb: edit_egg_path(1000) –> /eggs/1000/edit 这应该像我期望的那样工作吗? 我根本不介意手动修复它,但我很难找到RackBaseURI的值,所以我可以手动插入它,如果它存在的话。 我不想在某些环境中再次手动定义它,因为Rails必须已经知道它。

在完成重新加载之前,Rails 5重新加载器转移到下一个中​​间件

在rails 5开发模式中,在代码更改和刷新之后,它会触发重新加载器中间件来卸载/重新加载类。 但在重新加载重新加载之前,请求将移至下一个中间件。 重新加载器包含执行程序并查看executor.rb 。 似乎下一个中间件在run!后被调用run! 在complete!之前complete! 这与以下日志消息一致。 我想知道我是否可以确保下一个中间件仅在重新加载后调用。 我试图用Rails.application.executor.wrap , Rails.application.reloader.wrap和ActiveSupport::Dependencies.interlock.permit_concurrent_loads包装cusstomMiddle调用,但结果不是那些工作。 Rails版本:5.1 Ruby版本:2.4.1 我添加了以下日志消息,请参阅事件序列。 application.rb中 ActiveSupport::Reloader.before_class_unload do puts “Before class unload, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.after_class_unload do puts “After class unload, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.to_run do puts “Reloading, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.to_complete do puts “DONE Reloading, Thread Id: #{Thread.current.object_id}” end custom_middleware.rb def […]

在Rails 4.2.2中将请求参数截断,内容类型为“Application / xml”

我有以下观察: 我使用控制器和操作部署了一个示例Rails 4.2.2应用程序来接收POST请求。 现在如果我向这个应用程序发送POST请求,并且有一些POST主体说像{“1″=>”hello”,”2″=>”bye”}这样的哈希,并且请求的内容类型是”application/xml” ,我的Rails应用程序中没有收到任何参数。 如果我将同一请求的内容类型更改为其他内容,我将正确获取参数。 有人可以告诉我为什么Rails 4.2.2中存在这种行为,其POST请求的内容类型为”application/xml” 。

如何从我的Rack应用程序中删除“Server”HTTP响应标头

我试图从运行在Heroku上的ruby on rails应用程序中的http响应头中删除服务器信息,但是我被卡住了。 检查响应标头给了我: Server:thin 1.5.0 codename Knife 谁能指出我正确的方向?

尝试运行POW时出现隐秘错误

我为我的rails应用程序运行POW时有一个相当奇怪的错误消息。 我按照说明操作: – cd ~/.pow – ln -s /Users/mingyeow/Dailymuses-Server-Side 得到了这个: Error starting application Your Rack app raised an exception when Pow tried to run it. Error: ‘/Users/mingyeow/Dailymuses-Server-Side/.powrc’ failed to load: true && source ‘/Users/mingyeow/Dailymuses-Server-Side/.powrc’ > /dev/null && env > ‘/var/folders/cl/fd2wt82149x9trkxmsvqrt500000gn/T/pow.18625.1358760244196.27206’ Error: ‘/Users/mingyeow/Dailymuses-Server-Side/.powrc’ failed to load: true && source ‘/Users/mingyeow/Dailymuses-Server-Side/.powrc’ > /dev/null && env > ‘/var/folders/cl/fd2wt82149x9trkxmsvqrt500000gn/T/pow.18625.1358760244196.27206’ […]

改变Rack Middleware中的response.body

我正在尝试为Rails 4.2应用程序编写一些Rack Middleware,它使用gsub方法改变响应体。 我发现使用这样的模式的旧示例: class MyMiddleware def initialize(app) @app = app end def call(env) status, headers, response = @app.call(env) # do some stuff [status, headers, response] end end 我发现的是没有response.body setter方法response.body 。 还有另一种模式我可以开始修改身体吗?

Rails提供大型文件

我正在开发一个仅向登录用户提供大型video的应用程序。 为了保持这些video的私密性,我将它们放在Rails项目中的私有文件夹中,让Rails为它们提供服务,而不是使用公共文件夹并排除来自apache的请求(以避免直接链接到它们)。 我在控制器中的动作如下所示: def video respond_to do |format| format.mp4{ send_file File.join([Rails.root, “private/videos”, @lesson.link_video1 + “.mp4”]), :disposition => :inline, :stream => true } end end 一切都很完美,但只有小文件,一旦我尝试使用真实文件我收到错误: NoMemoryError (failed to allocate memory) 我在某个地方读到了将send_file用于大文件不是一个好习惯,但是使用其他方法,让apache为文件提供服务,我在向移动苹果设备提供文件时遇到了问题,因为他们没有发送HTTP_REFERER。 你知道这个内存限制有多小吗? 我的video从400MB到2GB(试图减少它们)。 我在这里找到的唯一问题是没有答案来处理rails中assets文件夹中的大型媒体文件

我的机架文件出了什么问题?

当我尝试启动我的unicorn服务器时,我有下一个堆栈跟踪:无法理解rackup文件有什么问题? 为什么它不可读? sites@bck:~/fatfreecrm$ /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/bin/unicorn_rails -E -D production -c /home/sites/fatfreecrm/config/unicorn.rb /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn/configurator.rb:600:in `parse_rackup_file’: rackup file (production) not readable (ArgumentError) from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn/configurator.rb:74:in `reload’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn/configurator.rb:65:in `initialize’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn/http_server.rb:102:in `new’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn/http_server.rb:102:in `initialize’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn.rb:30:in `new’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/lib/unicorn.rb:30:in `run’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/gems/unicorn-3.7.0/bin/unicorn_rails:208:in `’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/bin/unicorn_rails:19:in `load’ from /home/sites/.rvm/gems/ruby-1.9.2-p180@fatfreecrm/bin/unicorn_rails:19:in `’