草庐IT

match_first

全部标签

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 - 如何将 joins 方法与 first_or_initialize 一起使用而不是 find_or_initialize_by (Rails)?

有没有办法重写下面的流程,目前使用find_or_initialize_by,使用joins方法?对于上下文-我有users(员工)在系统中记录他们的attendances(user有很多attendances,考勤记录属于用户)。Attendance.find_or_initialize_by(user:User.find_by(name:'Bob'),date:Time.zone.today).update(...)#Updatesomecolumnsafterthis我正在尝试使用.joins重写它,如下所示:Attendance.joins(:user).where(users

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=========================================================

ruby-on-rails - 从 Rails 4.1.4 更新到 4.2.0 后,AR CollectionProxy 上的 "first!"引发 "undefined method [] for nil"

我开始从Rails4.1.4升级到Rails4.2.0。好像是第一!不再支持某些事件记录关联。first!(在ActiveRecord::Associations::CollectionProxy上)发生了什么导致它现在失败?如何修复该行为,使其像在4.1.4中一样工作?rails4.1:(byebug)user.organization.registration_codes#]>(byebug)user.organization.registration_codes.first!#rails4.2:(byebug)user.organization.registration_code

ruby-on-rails - 为什么 Rails 没有为我的 'match' 路线生成路线助手?

这是我在config/routes.rb文件中声明的两条路由:namespace:projectsdomatch"proj_rapports_contributeur/select"=>'proj_rapports_contributeur#select',:via=>:getmatch"proj_rapports_contributeur/generate/:id"=>'proj_rapports_contributeur#generate',:via=>:getend这是rails使用rakeroutes生成的结果路由和助手:projects_proj_rapports_contr

ruby - rake/Rspec : How to suppress/quiet/silent the first output line showing the command with --pattern ?

问题:如果我运行ServerSpec(基于RSpec)到Rake使用以下命令之一:rakerakespecrakespec:allrakespec:bundleexecrake...Rake将它执行的命令打印到stdout在serverspec输出之前:/usr/bin/ruby1.9.1-I/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/lib:/var/lib/gems/1.9.1/gems/rspec-support-3.1.2/lib/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/exe/rspec--pa