草庐IT

ruby-on-rails - 使用 rspec 调用特定的 url

我想在rspec中创建一个get请求。get:exec,{:query=>"bla",:id=>"something",:user_id=>"user"}这构建了一个URL,如:/user/query/something/exec?query=bla问题是我的Controller检查它收到的请求并且url必须如下所示:/user/query/something/_XXX_/exec?query=bla我怎样才能在rspec中做这样的事情?(XXX硬编码在routes.rb文件中。) 最佳答案 我假设您指的是Controller规范。

ruby - 如何通过 http 使用 Ruby 访问 URL 并读取输出?

到目前为止,我已经能够将它们拼接在一起:)beginopen("http://www.somemain.com/"+path+"/"+blah)rescueOpenURI::HTTPError@failure+=painting.permalinkelse@success+=painting.permalinkend但是我如何读取我要调用的服务的输出呢? 最佳答案 Open-URI扩展了open,因此您将获得一种返回的IO流:open('http://www.example.com')#=>#你必须阅读它才能获得内容:open('h

ruby-on-rails - ruby rails : redirect_to not working after create and save

我想在用户提交电子邮件后redirect_toslider_path。当前,仅显示成功消息而没有重定向。这是代码:classSplash::SubscribersController{:success=>success,:message=>message}.to_json}endendend 最佳答案 只需替换这部分代码:ifsuccessflash[:success]=messageredirect_toslider_pathelseflash[:error]=messageendredirect_toroot_path用这个:i

ruby-on-rails - Rails/Ruby创建数据库报错: Unable to load the EventMachine C extension

更新:eventmachinegem已安装并在我的gemfile中:eventmachine(1.0.0,0.12.10)请帮忙!尝试使用以下内容创建数据库:Fitzs-MacBook-Pro:twilio_insanityFitz$rakedb:create'返回以下错误:UnabletoloadtheEventMachineCextension;Tousethepure-rubyreactor,require'em/pure_ruby'rakeaborted!cannotloadsuchfile--rubyeventmachine/Users/Fitz/.rvm/gems/ruby

ruby-on-rails - 迪尔德 : Symbol not found: _rb_ary_new_from_values When trying to run foreman start

尝试运行“foremanstart”来执行我的rails文件时,我收到以下错误。dyld:Symbolnotfound:_rb_ary_new_from_valuesReferencedfrom:/Users/paulbattisson/.rvm/gems/ruby-2.1.1/gems/psych-2.0.5/lib/psych.bundleExpectedin:flatnamespace如果我运行railss那么应用程序可以正常启动,但是我想使用以下Procfile:web:bundleexecrackupconfig.ru-p$PORTresque:envTERM_CHILD=1

ruby-on-rails - Ruby on Rails URL 格式

我有一个RubyonRails应用程序,您可以在其中创建“帖子”。我开始使用脚手架生成器来生成标题(字符串)和正文(内容)。每个“帖子”都有一个id的url,例如/1、/2、/3等。有没有办法将其更改为一串随机字符,例如/49sl、/l9sl等?更新这是我为posts_controller.rb准备的classPostsController 最佳答案 Rails使用ActiveRecord对象的to_param方法将其解析为URL。假设您有办法生成这些唯一ID(将其称为IdGenerator),您可以执行以下操作:1-每当您持久化一

ruby - 在符号上链接 & to_proc

Rubyist众所周知,&会在符号上调用to_proc,所以[:a,:b,:c].map(&:to_s)相当于[:a,:b,:c].map{|e|e.to_s}#=>["a","b","c"]假设我想在to_s之后立即调用另一个方法,这两个实现将起作用:[:a,:b,:c].map{|e|e.to_s.upcase}[:a,:b,:c].map(&:to_s).map(&:upcase)我的问题是,有没有一种方法可以将&Symbol#to_proc调用链接到一个参数中?像这样的东西:[:a,:b,:c].map(&:to_s:upcase)谢谢! 最佳答案

ruby-on-rails - 在 html 字符串中自动链接 URL 和图像

你好,我有一个这样的字符串:"http://vimeo/2342343http://nerto.it/logo.pngtrytowritehttp://vimeo/2234923"我必须将它转换成这样的字符串:"http://vimeo/2342343trytowritehttp://vimeo/2234923"那么我如何获取每个元素并对其进行转换?谢谢 最佳答案 您可以使用auto-linkfunction将链接转换为实际的anchor标记。auto_link(text_to_convert)*注意:方法已弃用或移动此方法已弃用或

ruby - RVM 系统范围的安装脚本 url 已损坏——什么是替换?

我的RVM系统级安装脚本损坏了,无论是LinodeStackScripts还是Chef-soloRecipes的形式。根据RVM网站上的说明,我的脚本以root身份执行以下命令以在系统范围内安装RVM:echo"InstallingRVMsystem-wide">>$logfilebash>/etc/profile上面的关键部分是urlhttp://bit.ly/rvm-install-system-wide。截至今天,2011年3月24日,此网址不再提供服务。它会导致GitHub404错误。RVM网站上的以下URL用于包含系统范围安装的说明:http://rvm.beginrescu

ruby-on-rails - 我的 Rails 4 应用程序上的每个 link_to 都被调用了两次

我的Rails4应用程序遇到一些异常行为。每次我单击View中的link_to时,我的Controller操作都会被调用两次。例如:在我的root_url中,我对users_profile有这个标准调用:"logout-button")%>当我单击此链接时,我的控制台显示以下输出:StartedGET"/users/profile"for127.0.0.1at2013-11-2520:45:53-0200ProcessingbyUsers::SessionsController#profileasHTMLUserLoad(0.7ms)SELECT"users".*FROM"users"