Tag:

没有任何框架的Ruby网页从头开始

我正试图从头开始学习ruby for web。 我知道PHP,我是ruby的新手。 我不想在开始时使用任何框架。 尝试创建简单的2-3页练习。 我搜索了很多,但没有任何例子来创建ruby和机架的网页,并在任何浏览器中运行它。 如果您有任何url或在线资料可以开始,请分享。

这是Rack中的错误吗?

我正在尝试使用java客户端将多部分内容(文件和一些字符串)发布到localhost上的Sinatra服务器。 似乎服务器不喜欢POST消息。 堆栈跟踪是: ERROR NoMethodError: undefined method `rewind’ for “hi”:String D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:581:in`block in parse_multipart’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`loop’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`parse_multipart’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:270:in `parse_multipart’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:148:in `POST’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/methodoverride.rb:15:in `call’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `block in call’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303:in `synchronize’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `call’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/content_length.rb:13:in `call’ D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/handler/webrick.rb:52:in `service’ D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service’ D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run’ D:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread’ 我的服务器在post消息中打印出params。 以下是我的java客户端的内容: Content-Disposition: form-data; name=”file”; filename=”fff.jpg” Content-Type: image/jpeg Content-Transfer-Encoding: binary # Content-Disposition: form-data; name=”jjj” […]

Ruby on Rails:修补Rack并部署它

我需要使用以下补丁修补Rack: http : //github.com/rack/rack/commit/dae12e088592ee69545b5f2f81b87f4959859164 这样做的最佳做法是什么? 我应该打开包装,应用补丁,然后重新包装gem并用capistrano运送它以确保我的gem版本到达目标服务器? 我可以直接将机架放入供应商/插件/并依赖它首先加载到系统范围的gem之前吗? 我想采取阻力最小的路径,并且能够轻松地将其部署到许多环境中。

Gitlab机架攻击安装

我正在安装gitlab并遵循Gitlab安装指南的所有说明。 一切正常,但在步骤“初始化数据库并激活高级function”失败了! https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md 我收到此错误消息。 rake aborted! uninitialized constant Rack::Attack /home/git/gitlab/config/application.rb:82:in `’ /home/git/gitlab/config/application.rb:13:in `’ /home/git/gitlab/config/application.rb:12:in `’ /home/git/gitlab/Rakefile:5:in `require’ /home/git/gitlab/Rakefile:5:in `’ (See full trace by running task with –trace) 在application.rb文件中,我按照说明中的说法取消注释了该行。 # Enable rack attack middleware # Find and uncomment the line ‘config.middleware.use Rack::Attack’

机架错误 – LoadError:无法加载此类文件

试图通过tekpub机架教程但遇到此错误。 Boot Error Something went wrong while loading app.ru LoadError: cannot load such file — haiku 在我尝试运行的应用程序所在的目录中有一个名为haiku.rb的文件,但是在尝试运行程序时出现上述错误。 这是代码: class EnvironmentOutput def initialize(app=nil) @app = app end def call(env) out = “” unless(@app.nil?) response = @app.call(env)[2] out+=response end env.keys.each {|key| out+=”#{key}=#{env[key]}”} [“200”,{“Content-Type” => “text/html”},[out]] end end require ‘haml’ require ‘haiku’ class MyApp def call(env) poem = […]

路由机架问题

我正在使用Ruby on Rails 3,我想将一些URL路由到一些Rack中间件。 也就是说,如果用户尝试浏览http://.com/api/user/1 ,系统应考虑在Rack文件之前运行,然后继续执行请求。 我有一个Rack :: Api:用户位于lib/rack/api/user文件夹中。 从RoR官方文档中我发现了这个: Mount a Rack-based application to be used within the application. mount SomeRackApp, :at => “some_route” Alternatively: mount(SomeRackApp => “some_route”) All mounted applications come with routing helpers to access them. These are named after the class specified, so for the above example the helper is either […]

如何在不同版本的gem之间切换?

我在本地计算机上安装了三个版本的机架( rack (1.4.1, 1.3.6, 1.3.5) )。 对于某些gem(如Cucumber ),它需要激活较低版本的rack ? 我试过bundle但没有好处。 执行时, cucumber仍将使用系统版本1.4.1的激活机架。 Bundle指定应安装哪个gem但不确保激活哪个gem 。 我怎么能激活某个版本的rack ?

机架1.3.2的问题。 您已经激活了机架1.3.2,但您的Gemfile需要机架1.2.3

我有debian的乘客3.0.9,gem机架1.3.2和1.2.1。 使用带有乘客e bundler的rails 3.0应用程序,我有这样的错误: 您已经激活了机架1.3.2,但您的Gemfile需要机架1.2.3。 考虑使用bundle exec。 使用rails 3.1就可以了。 我无法使用rails 3.0启动应用程序,但只能使用3.1。 Passnnger加载第一个机架1.3.2并且不要在捆绑器的gem上装载机架1.2.3

为什么机架响应体不是字符串?

他们的文档中的经典hello world示例, class HelloWorld def call(env) return [200, {}, [“Hello world!”]] end end 我的问题是为什么第三个值是[Hello world!“],而不是”Hello world“?来自他们的doc, Body必须响应每个,并且只能产生String值。 Body本身不应该是String的实例,因为这将在Ruby 1.9中破坏。 为什么身体需要对每个人做出回应? 在什么情况下重要?

Rack:如何将URL存储为变量?

我正在写一个简单的静态Rack应用程序。 查看下面的config.ru代码: use Rack::Static, :urls => [“/elements”, “/img”, “/pages”, “/users”, “/css”, “/js”], :root => “archive” map ‘/’ do run Proc.new { |env| [ 200, { ‘Content-Type’ => ‘text/html’, ‘Cache-Control’ => ‘public, max-age=6400’ }, File.open(‘archive/splash.html’, File::RDONLY) ] } end map ‘/pages/search.html’ do run Proc.new { |env| [ 200, { ‘Content-Type’ => ‘text/html’, ‘Cache-Control’ => ‘public, max-age=6400’ […]