jjzjj

filter-var

全部标签

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-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

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 - var_dump 并像 php 一样死去,在 ruby​​ on rails 中(在 ruby​​ on rails 中调试)

这可能是重复的问题。但是我无法显示对象。我是ruby​​的新手,尝试过像var_dump和print_r这样的调试,然后在php中die/p>这是我的代码。@brand_id=Brand.maximum("brand_id")我试过下面的方法1putsYAML::dump(@brand_id)2logger.debug{@brand_id.inspect}请问谁能帮我解决一下吗? 最佳答案 Rails只会将View输出到浏览器。任何其他输出都发送到服务器上的STD_OUT。从View中调试很简单:但是从Controller或模型内部

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

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

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所必需的)而不影响最终用户体验(例如:我的应用程序网

ruby-on-rails - rails 是如何实现 before_filter 的?

我对Rails如何实现像before_filter这样的过滤器很感兴趣。但是看了源码还是一头雾水。我注意到rails的框架维护了一个filter_chain,并在目标方法之前运行过滤器。但是,我不明白一个重要的过程:rails是如何捕获方法调用的?我的意思是,例如,我有一个类Dog,并为方法bark设置了一个before_filter。当我调用dog.bark时,rails应该以某种方式捕获此调用,并改为运行其修改后的方法。但是,我在源代码中没有找到这样的代码。任何人都可以告诉我这个想法或指出代码所在的位置吗? 最佳答案 当您设置b

ruby-on-rails - Rails before_filter 用于 Controller 中的特定操作

defnewbefore_filterdoredirect_to"/"unlesscurrent_admin||current_companyflash[:notice]='Youdonthaveenoughpermissionstobehere'unlesscurrent_admin||current_companyendCODECODECODEenddefeditbefore_filterdoredirect_to"/"unlesscurrent_admin.id=5flash[:notice]='Youdonthaveenoughpermissionstobehere'unles