jjzjj

private-class

全部标签

ruby-on-rails - Rails 3 中私有(private)消息建模的首选方式

我计划在成员之间实现一个私有(private)消息系统。我想知道对此的首选方法是什么。要求是我应该能够像这样轻松地检索它们@user.conversations#ShouldreturnUserobjectsthatIsentorreceivedmessagesfrom(butnotme)@user.conversations.messages#Messagesfromallorspecificuserobjects.@user.conversations.messages.unread#Unreadmessages调用@user.conversations时应该只检索向我发送消息的人

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

我正在尝试在prawn类中使用rails3.2助手,但rails抛出:undefinedmethod`number_with_precision'for#Prawn类classQuotePdfControllerdefshow@quote=current_user.company.quotes.where(:id=>params[:id]).firsthead:unauthorizedandreturnunless@quoterespond_with@quote,:layout=>!params[:_pjax]do|format|format.pdfdosend_dataQuotePd

ruby-on-rails - PinsController#index : declare the formats your controller responds to in the class level 中的运行时错误

在我的Rails应用程序上工作时,我在终端中使用以下命令创建了一个“Pins”脚手架:railsgeneratescaffoldPinsdescription:string--skip-stylesheets这会在我的应用程序中创建脚手架,然后我运行:rakedb:migrate一切顺利。我没有更改任何生成的页面,但是当我最终尝试访问localhost:3000上的新脚手架时,出现以下错误:RuntimeErrorinPinsController#indexInordertouserespond_with,firstyouneedtodeclaretheformatsyourcontr

ruby - 为什么 Ruby 会针对私有(private)属性抛出警告

以示例类为例:#in./example.rbclassExampleprivateattr_accessor:nameend当我在详细模式下运行它时,Ruby会向我发出警告:$ruby-W2./example.rbexample.rb:3:warning:privateattribute?为什么不推荐这样做? 最佳答案 因为在大多数情况下,定义一个从外部看不到的getter/setter意义不大。我们通常使用attr_accessor只是为了在类之外暴露一个实例变量。但是,private关键字使生成的getter/setter方法对

ruby-on-rails - rails : how to extend a gem's ActiveRecord child class?

我在扩展一个在gem中定义并且是ActiveRecord::Base的子类的类时遇到问题。我唯一想扩展这个类的是:有很多:promos然而,扩展倾向于排除原始类。我得到的错误:PGError:ERROR:relation"sites"doesnotexistLINE4:WHEREa.attrelid='"sites"'::regclass^:SELECTa.attname,format_type(a.atttypid,a.atttypmod),d.adsrc,a.attnotnullFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.a

Ruby module_function,调用模块的私有(private)方法,在模块的类方法样式中调用显示错误

test_module.rbmoduleMyModuledefmodule_func_aputs"module_func_ainvoked"private_bendmodule_function:module_func_aprivatedefprivate_bputs"private_binvoked"endendclassMyClassincludeMyModuledeftest_modulemodule_func_aendend从类中调用模块函数c=MyClass.newc.test_module输出1:$rubytest_module.rbmodule_func_ainvoked

ruby - "const_missing"定义中缺少常量和 "class << self"

在定义const_missing时,我对Ruby的行为感到非常困惑和class中的其他类方法定义而不是使用defself.foo句法。我正在尝试做这样的事情:classFooclass我主要使用class定义类方法的语法。但是,它没有按预期工作。const_missing永远不会被调用。以上结果导致NameError。像这样定义这两种方法按预期工作:defself.fooputsMISSINGenddefself.const_missing(name)puts"#{name}missing"end我认为classsyntax只是定义类方法的另一种方式,但完全等同于defself.foo

ruby-on-rails - 为类调用私有(private)方法选择 - Rails

我的Controller中有以下代码:array=Contact.select(:name).distinct想法是,这将创建一个包含所有具有唯一:name属性的Contact模型的数组。但是,它抛出了这个错误:NoMethodError(为Contact:Class调用了私有(private)方法“select”)这里有什么误会?值得一提的是,调用这行代码的方法并未在Controller中定义为私有(private)。编辑:这是实际的代码:ControllerclassFluidsurveysController型号classContactincludeActiveModel::Mo

ruby-on-rails - 无法从类内部访问私有(private)方法?

为什么我无法从类封装的方法中访问下面代码中的私有(private)方法check_url?classLink{:in=>[true,false]}validates:url,:presence=>true#===============================================================#=classmethods(accessiblefromoutsidewithoutaninstance)=#===============================================================classurl,:i

ruby - Module.private_constant 有什么作用?有没有办法只列出私有(private)常量?

从Ruby1.9.3开始,我们可以创建私有(private)常量:moduleMclassC;endprivate_constant:Cend是否有关于此功能的良好文档?有没有办法只获取类似于调用constants的私有(private)常量的名称 最佳答案 在Ruby1.9.3之前,没有私有(private)常量这样的东西。不过,要获得所有常量的列表,您可以简单地使用constants。moduleModCONST="value"endMod.constants#=>[:CONST]从1.9.3开始,添加了private_cons