草庐IT

partial-match

全部标签

ruby 心印 : regex parentheses "capture" matched content?

我正在浏览about_regular_expressions.rb并且不明白这里到底发生了什么:deftest_variables_can_also_be_used_to_access_capturesassert_equal"Gray,James","Name:Gray,James"[/(\w+),(\w+)/]assert_equal"Gray",$1assert_equal"James",$2end在我看来,似乎在正则表达式中使用括号会在幕后创建两个新变量($1和$2)。这是正确的吗?但后来我这样做了:deftest_variables_can_also_be_used_to_a

ruby-on-rails - 错误 : SELECT DISTINCT ON expressions must match initial ORDER BY expressions

我的要求是得到不同的记录并按顺序User.joins('INNERJOINreport_postsONposts.id=report_posts.post_id').select('DISTINCTON(report_posts.post_id)posts.idasreport_posts.idasreported_id,report_posts.reported_at').order('report_posts.reported_atdesc')我知道这在postgresql中是不可能的,我已经读过这个PostgresqlDISTINCTONwithdifferentORDERBY我

ruby-on-rails - Xpath 2.0 - xmlXPathCompOpEval : function matches not found

我在我的Rails项目中运行Xpath2.0,并尝试使用它提供的matches()函数,如下所示:page=Mechanize.new.get('http://www.example.com').parserpage.search("//a[matches(text(),'lagerfordon','i')]").first.text抛出以下错误:RuntimeError:xmlXPathCompOpEval:functionmatchesnotfound我做错了什么? 最佳答案 Nokogiri(Mechanize构建于其上)使用

ruby-on-rails - Rails_Admin 显示路由错误 "No route matches {:controller=>"home"}"

我按照说明安装了Rails_Admin,并且也在使用Devise。当我尝试导航到“/admin”时,出现以下错误:RoutingErrorNoroutematches{:controller=>"home"}这是我的routes.rb:Ot::Application.routes.drawdoresources:badgeshipsresources:badgesresources:profilesresources:universitiesresources:degreesresources:jobsresources:resourcesresources:communitiesre

ruby-on-rails - Rails devise 求助路由报错 No route matches "/sessions/user"

当我登录我的页面时,我会自动转到路线:http://localhost:3000/sessions/user我得到这个错误:RoutingErrorNoroutematches"/sessions/user"我在此处的用户文件夹中创建了一个名为sessions_controller.rb的Controller:classUsers::SessionsController"Youhavebeenloggedout."enddefcreateuser=User.authenticate(params[:login],params[:encrypted_password])ifuserses

ruby - Rails - 如何处理不存在的路由 ("No route matches [GET]")?

我的路线看起来像match'about'=>'company#about'当我设置为urlhttp://localhost:3000/aboutttt时,我收到错误消息Noroutematches[GET]"/aboutttt"我想给用户更好的反馈。我认为最好的解决方案是将应用程序重定向回来,或者在应用程序的主页上重定向,但在出现上述错误时以任何方式存在于路由中以设置默认路由? 最佳答案 当你在开发的时候。通过设置在config/environments/development.rb中进行更改:config.consider_all

ruby-on-rails - rails 4 : No route matches - issue with relationships missing id key

我希望有人能帮助我。我遇到以下问题:Noroutematches{:action=>"show",:controller=>"stocks",:stockpile_id=>#,:id=>nil,:format=>nil}missingrequiredkeys:[:id]访问以下URL时:/admin/stockpiles/3/stocks/我的路线是这样的:scope'/admin'doroot:to=>'admin#index',:as=>'admin'resources:stockpiles,:companiesscope:path=>'stockpiles/:stockpile_

ruby - 类型不匹配 : String given - Trying to match strings in ruby

我在Rails中使用authlogic-connect。我正在使用一个简单的haml模板,我不想在其中显示已添加的授权提供者。%h2MyAccount%form.authentication_form{:action=>connect_path,:method=>:post}%fieldset%input{:type=>:hidden,:name=>:authentication_type,:value=>:user}%legendAddanotherOauthorOpenIDprovider..oauth_providers%ul-%w(googlefacebooktwitterya

ruby - RegExp#match 只返回一个匹配项

请解释一下,为什么match()只返回一个匹配项,而不是四个(例如):s='aaaa'p/a/.match(s).to_a#=>["a"]奇怪的是,分组match()返回两个匹配,独立于实际匹配计数:s='aaaa'p/(a)/.match(s).to_a#=>["a","a"]s='aaaaa'p/(a)/.match(s).to_a#=>["a","a"]感谢您的回答。 最佳答案 需要使用.scan()进行多次匹配:ps.scan(/a/).to_a通过分组,整体匹配得到一个结果,每个组得到一个结果(使用.match()时。这两

ruby-on-rails - Rails Devise 路由错误 - "No route matches"( Controller = >"devise/sessions")

编辑2:看起来对我来说一个快速的临时修复是在我的link_to_unless_current和current_page方法中的Controller名称前面添加一个正斜杠“/”。例如'/sites',:action=>action)?'active':''%>">'/sites',:action=>action})%>这里是关于我遇到的问题的更多信息,以防其他人遇到同样的事情。https://github.com/plataformatec/devise/issues/471=========================================================