草庐IT

index-filter

全部标签

ruby-on-rails - Elasticsearch /轮胎 : How do I filter a boolean attribute?

我想过滤我类(class)的私有(private)bool值,以便它只显示非私有(private)但对我不起作用的资源。(我大大简化了代码)mappingdoindexes:private,type:"boolean"indexes:name,type:"string"endenddefself.search(params)tire.search(load:true,page:params[:page],per_page:20)doquery{stringparams[:query]}ifparams[:query].present?#SofarI'vetried...#filter:

ruby - 多个 Controller 之间共享的 before_filter 放在哪里

我有多个Controller,它们都使用相同的before_filter。为了让事情保持干燥,这个方法应该放在哪里以便所有Controller都可以使用它?模块似乎不是正确的位置,但我不确定为什么。我不能将它放在基类中,因为Controller已经有不同的父类(superclass)。 最佳答案 如何将您的before_filter和方法放在一个模块中,并将其包含在每个Controller中。我会将此文件放在lib文件夹中。moduleMyFunctionsdefself.included(base)base.before_filt

ruby - 如何将 before_filter 应用于 Rails 3.2.11 中每个 Controller 的每个操作?

我想验证用户是否在对服务器的每个请求中登录。类似于::before_filterverify_logged_in我应该把before_filter放在哪里,以便它适用于所有Controller操作和所有请求? 最佳答案 为确保过滤器适用于所有操作,将其放在application_controller.rb中。 关于ruby-如何将before_filter应用于Rails3.2.11中每个Controller的每个操作?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - 为什么在 Controller 被子类化时 Rails before_filter 被调用两次?

我在使用Rails2.3.5,我遇到了这个问题:classBaseController[:index]endclassChildController[:index,:show,:other,:actions]end问题是在ChildController上,过滤器之前的:foo被调用了两次。我已经尝试了很多解决这个问题的方法。如果我不在子项中包含:index操作,则永远不会为该操作调用它。我找到的解决方案有效,但我认为它非常难看skip_before_filter:foobefore_filter:foo,:only=>[:index,:show,:other,:actions]有没有更

ruby-on-rails - Ruby on Rails before_filter 与 ruby​​ 的初始化

只是我的一个想法。下面有什么区别before_filterclassApplicationControllerruby初始化classApplicationControllerruby的初始化方法在rails中是否按预期工作?如果是,那么我们是否可以在必须将过滤器应用于Controller中的所有操作的地方使用初始化? 最佳答案 对于每个请求,您确实会得到一个新的ApplicationController实例,但是这里最大的禁忌是您试图覆盖ActionController::Base#initialize的核心行为不调用父行为。Ap

ruby - 大多数方法中的 "This is a stub, used for indexing"?

我正在研究cursesgem的curses.rb,我发现它无处不在:defattrset(attrs)#Thisisastub,usedforindexingend#bkgdset(ch)##Manipulatethebackgroundofthecurrentwindow#withcharacterInteger+ch+##seealsoCurses.bkgdsetdefbkgdset(ch)#Thisisastub,usedforindexingend#bkgd(ch)##Setthebackgroundofthecurrentwindow#andapplycharacterInt

ruby - ruby 中的最后一个索引是否有等效的 Array#find_index ?

Array#find_index允许您找到第一个项目的索引等于一个对象,或者使传递给它的block评估为真Array#rindex可以让您找到等于object的最后一项的索引,但是有没有什么可以让您找到的索引使block传递给它的最后一项返回true?否则,我是否应该做类似的事情last_index=array.length-1-array.reverse.find_index{|item|item.is_wanted?} 最佳答案 在Ruby1.9.2中Array#rindex接受block:http://apidock.com/

Ruby 数组 reverse_each_with_index

我想在数组上使用类似reverse_each_with_index的东西。例子:array.reverse_each_with_indexdo|node,index|putsnodeputsindexend我看到Ruby有each_with_index但它似乎没有相反的。还有其他方法吗? 最佳答案 如果你想要数组中元素的真实索引,你可以这样做['Seriously','Chunky','Bacon'].to_enum.with_index.reverse_eachdo|word,index|puts"index#{index}:#{

ruby-on-rails - Sprockets::CircularDependencyError in Store#index

我正在遵循手册《使用Rails进行敏捷Web开发》第4版,但我在rails3.1中遇到了sprocketcss的问题。代码css是:http://media.pragprog.com/titles/rails4/code/rails31/depot_e/app/assets/stylesheets/application.css.scss如果我修改app/assets/stylesheets/aplication.css.scss的css代码,我会遇到下一个错误:Sprockets::CircularDependencyErrorinStore#indexShowing/home/ub

ruby-on-rails - 'after_filter' 如何/何时工作/运行?

我正在使用RubyonRails3.1,我想知道(出于性能原因)after_filter是否在呈现View文件后运行。也就是说,当用户访问我的应用程序URL时,他/她应该显示的相关View文件在after_filter运行之前呈现,或者after_filter在运行之前呈现查看文件是否呈现?换句话说,应用程序服务器在运行after_filter或它等待运行after_filter方法,然后才发送该View数据?P.S.:我打开这个问题是因为我想运行一些系统更新(注意:这些更新不会影响View输出数据并且不会“被使用”通过“/”View所必需的)而不影响最终用户体验(例如:我的应用程序网