草庐IT

match_string

全部标签

ruby-on-rails - rails 引擎 : rake routes show its routes but on rspec execution "No route matches" is thrown

我正在尝试测试我的应用程序正在使用的引擎内部的Controller。规范不在引擎中,而是在应用程序本身中(我试图在引擎中进行测试,但也遇到了问题)。我的引擎有以下routes.rb:Revision::Engine.routes.drawdoresources:steps,only:[]docollection{get:first}endend引擎正常挂载在应用routes.rb上:mountRevision::Engine=>"revision"当我运行rakeroutes时,在最后一行我得到:RoutesforRevision::Engine:first_stepsGET/step

ruby - 类型错误 : no implicit conversion of Hash into String

尝试解析一些JSON,为什么text是空的?期望的输出:text应该返回Helloworld\n\nApple,Harbor\n\nBanana,Kitchen\n\nMango,Bedroomtext="Helloworld"json='{"fruits":[{"name":"Apple","location":"Harbor"},{"name":"Banana","location":"Kitchen"},{"name":"Mango","location":"Bedroom"}]}'fruits=JSON.parse(json)defformat_fruits(fruits)fr

ruby - 安装 RDoc 文档时出错 : incompatible encoding regexp match

上周,在一些gem安装或gem更新操作中,我收到了与这些类似的错误:ERROR:Whilegeneratingdocumentationforsinatra-1.3.1...MESSAGE:errorgeneratingC:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/doc/sinatra-1.3.1/rdoc/README_de_rdoc.html:incompatibleencodingregexpmatch(UTF-8regexpwithIBM437string)(Encoding::CompatibilityError)类似的:E

ruby - Codecademy "converting between symbols and strings" ruby 类(class)

这些是Codecademy的说明:Wehaveanarrayofstringswe'dliketolateruseashashkeys,butwe'drathertheybesymbols.Createanewarray,symbols.Use.eachtoiterateoverthestringsarrayandconverteachstringtoasymbol,addingthosesymbolstosymbols.这是我写的代码(提供了strings数组):strings=["HTML","CSS","JavaScript","Python","Ruby"]symbols=[]

ruby - 在 Ruby 中,String() 和 #to_s 有什么区别

String(1.1)==(1.1).to_s=>trueString(1.1)===(1.1).to_s=>true这两种强制方式有区别吗?如果可以,你能演示一下吗? 最佳答案 docsfortheStringmethod说:ConvertsargtoaStringbycallingitsto_smethod.所以通常它们是相同的,但也有一些差异——尽管您不太可能真正看到它们。String()检查其参数的类,如果它还不是String,则对其调用to_s。直接调用to_s意味着无论如何都会调用该方法。考虑类:classMyStrin

ruby-on-rails - 为什么 String#gsub 的内容加倍?

s="#main='quotes's.gsub"'","\\'"#=>"#main=quotes'quotes"这似乎是错误的,我希望得到"#main=\\'quotes\\'"当我不使用转义字符时,它会按预期工作。s.gsub"'","*"#=>"#main=*quotes*"所以一定有转义的事情。使用ruby1.9.2p290我需要用反斜杠和引号替换单引号。更多的不一致:"\\'".length#=>2"\\*".length#=>2#Asexpected"'".gsub("'","\\*").length#=>2"'a'".gsub("'","\\*")#=>"\\*a\\*"(

ruby - 是否有 Ruby string#blank?方法?

String#blank?非常有用,但存在于Rails中,而不存在于Ruby中。Ruby中是否有类似的东西来替换:str.nil?||str.empty? 最佳答案 据我所知,普通Ruby中没有这样的东西。您可以像这样创建自己的:classNilClassdefblank?trueendendclassStringdefblank?self.strip.empty?endend这将适用于nil.blank?和a_string.blank?您可以将其扩展(就像rails一样)用于true/false和一般对象:classFalseCl

ruby - 什么是枚举器对象? (使用 String#gsub 创建)

我有一个属性数组如下,attributes=["test,2011","photo","198.1x198.1cm","Photo:ManuPKFullScreen"]当我这样做时,artist=attributes[-1].gsub("Photo:")partist我在终端中得到以下输出#想知道为什么我得到一个枚举器对象作为输出?提前致谢。编辑:请注意,我做的不是attributes[-1].gsub("Photo:",""),而是attributes[-1].gsub("Photo:")所以想知道为什么枚举器对象返回到这里(我期待一条错误消息)以及发生了什么。?ruby-1.9.2

ruby-on-rails - `merge' :string <%= form_for %> helper 的未定义方法 '####'

我有一个表单,在发布时呈现另一个表单。我想做的是将参数从第一种形式传递到第二种形式的某些隐藏字段中。第二种形式是使用form_for形式助手,而我试图做的是让它接受传递给它的参数。表单如下所示:"btnbtn-largebtn-success"%>当我做类似的事情时这个Action给我错误:NoMethodErrorinFind_numbers#createShowingC:/Sites/dentist/app/views/phones/new.html.erbwhereline#17raised:undefinedmethod`merge'for"1231231234":String

ruby - 无法将 Symbol 转换为 String

我有以下Ruby代码,直接取自GettingStartedwithRails指南defcreate@post=Post.new(post_params)@post.saveredirect_to@postendprivatedefpost_paramsparams.require(:post).permit(:title,:text)end当我运行上面的Create时,出现以下错误。can'tconvertSymbolintostring 最佳答案 您似乎正在尝试使用强参数。你得到这个错误cannotconvertsymbolint