草庐IT

dispatch_get_global_queue

全部标签

ruby - 如何在具有通配符的 RSpec 中请求(GET/POST)路由

我在Rails中有这条(公认的丑陋的)路线:scope'/software'dopost'/:software_id/:attachment_id/event/*event'=>'software#post_event',as:'post_event'end(如果不是遗留API,我会更改它)我正在为它编写一个RSpec测试。rakeroutes给我:post_eventPOST/software/:software_id/:attachment_id/event/*event(.:format)api/version1301/software#post_event我的测试是这样的:de

ruby-on-rails - minitest_plugin.rb :9 getting wrong number of arguments

~/Sites/sample_app$railstestRunningviaSpringpreloaderinprocess24338Runoptions:--seed58780Running:..Finishedin0.292172s,6.8453runs/s,6.8453assertions/s./var/lib/gems/2.3.0/gems/railties-5.1.0/lib/rails/test_unit/minitest_plugin.rb:9:in`aggregated_results':wrongnumberofarguments(given1,expected0)(

ruby-on-rails - rails : Where does new_*something*_path variable get set up?

我为“消息”创建了一个脚手架,并且new_message_path和edit_message_path(用于link_to's)都已设置,但现在我已经创建了app/views/messages/sent.html.erb,我想做类似的内容,但我不知道该怎么做。我明白了undefinedlocalvariableormethod`sent_message_path'for# 最佳答案 这些方法是在定义路由时自动创建的,对于RESTful路由,它们遵循可预测的约定。运行“rakeroutes”是查看生成的所有路由的有用方法。我建议您阅读

ruby - 使用参数重定向 POST/GET 请求的 Sinatra 应用程序

我正在迁移服务器,但不幸的是,旧服务器IP已硬编码在我的iPhone应用程序中。显然,我将提交一个更新,将API端点设置到我的新服务器,但与此同时,我需要在旧服务器上设置一个应用程序,将所有请求重定向到新服务器。我听说Sinatra非常适合这个。require'sinatra'get"/foo/bar"doredirect"http://new-server.com/foo/bar",303endpost"/foo/bar"doredirect"http://new-server.com/foo/bar",303end问题是它们不会随请求一起转发GET或POST参数。我在Sinatra

ruby - Ruby 的 Object#const_get 是如何工作的?

我最近发现Ruby(2.2.1)有一些“有趣”的行为。moduleFooclassFooendclassBarendendFoo.const_get('Foo')#=>Foo::FooFoo.const_get('Bar')#=>Foo::BarFoo.const_get('Foo::Foo')#=>FooFoo.const_get('Foo::Bar')#=>NameError:uninitializedconstantFoo::Foo::BarFoo.const_get('Foo::Foo::Bar')#=>Foo::BarFoo.const_get('Foo::Foo::Foo:

适用于多行的 Ruby 'gets'

使用IRB,我想输入一个多行字符串,以便从中删除某些字符。“gets”只允许单行-多行是否有类似的功能。ASCII_project.rb(main):002:0*puts="What'sthetextyouwanttostrip?"=>"What'sthetextyouwanttostrip?"ASCII_project.rb(main):003:0>str=gets我现在想粘贴一段文本-因为新行它不起作用。这就是为什么我要收集多行这是代码#encoding:CP850puts="What'sthetextyouwanttostrip?"str=getsstr.gsub!(/\P{AS

ruby-on-rails - 带@global gem 的 Ruby/RVM - bundle 运行失败,显示 `require' : cannot load such file — bundler (LoadError)

我学习了1个月的linux。当我尝试从MigratingfromMySQLtoPostgresonHeroku开始执行所有步骤时我遇到无法处理的错误。当我尝试从源代码安装mysqltopostgresgem时:$gitclonehttps://github.com/maxlapshin/mysql2postgres.git$cdmysql2postgres$bundleinstall$gembuildmysqltopostgres.gemspec$sudogeminstallmysqltopostgres-0.2.20.gem我在$bundleinstall上有一个错误:/home/f

ruby - Rails 3 - 测试 Controller 的 GET 方法 - 尝试使用 JSON 并出现 406 错误

我有一个简单的Controller,它指定:respond_to:json当我尝试构建这样调用它的功能测试时:test"GET"doget'index',:format=>:jsonend一切正常。但是,如果我尝试像这样传递查询参数:test"GET"doget'index',{:my_param='1234'},:format=>:jsonend我收到Controller返回的406错误。如果我通过response.inspect转储响应,我可以看到@status=406和@header的内容类型为文本/html。如果我通过response.inspect为不传递查询参数的简单情况转

ruby-on-rails - 将 form_for 标签与 get 方法一起使用

我正在尝试使用get方法提交表单。早些时候我尝试用form_tag做类似的事情并且它工作正常但现在当我更改为form_for标签时,这似乎不起作用。filter_path,:method=>:get)do|f|%>我收到一个无路由错误。 最佳答案 如果需要,您可以使用:html传递原始HTML属性。对于Rails3:filter_path,:html=>{:method=>'GET'})do|f|%>更新并且在Rails4中,根据下面@andre.orvalho的建议,可以直接提供method参数:

ruby - 导轨 : how to get a file extension/postfix based on the mime type

我的问题是,RubyonRails是否具有类似于以下的功能:file_content_type=MIME::Types.type_for(file).first.content_type这将返回特定mime类型的文件扩展名或后缀?所以如果我传入'image/jpeg'函数将返回'jpg'寻找一种比编写完成相同工作的case语句更简洁的编码方式。 最佳答案 Rack::Mime具有这种能力(Rack是Rails的依赖):require'rack/mime'Rack::Mime::MIME_TYPES.invert['image/jpe