jjzjj

class-fields

全部标签

ruby - Redmine邮箱配置: "undefined method ` email_delivery =' for ActionMailer::Base:Class"

我在第一次安装Redmine后为Redmine配置电子邮件通知。我创建了/etc/redmine/default/email.yml并添加了:#Outgoingemailsettingsproduction:email_delivery:delivery_method::smtpsmtp_settings:address:smtp.example.comport:25domain:example.comauthentication::loginuser_name:examplepassword:example访问时http://redmine/我遇到一个应用程序异常:“ActionMa

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-on-rails - rails : accessing field value from model method

刚开始学习Rails(三)。我正在努力寻找如何做一些可能完全微不足道的事情:从该模型的方法内部访问模型实例字段的值。以我为例:defformal_name@title+""+@forename+""+@surnameend所有三个@properties(它们都是数据库中表上的字段)都返回nil。他们不应该。令人难以置信的是,http://guides.rails.info/并未讨论如何访问字段,google什么也找不到。顺便说一句,我来自Django,这里的东西很明显。 最佳答案 @语法用于实例变量,这些实例变量(例如)在Contr

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 - "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 - rails : Human-friendly date format for text_field

我有一个存储为日期时间值的birth_date字段。默认的railsformhelpers吐出一种不太友好的格式,例如“2008-06-1022:33:19.000000”。下面是Vanillarails方式。"20"%>我怎样才能简单地应用一种格式?我尝试了各种方法,例如strftime应该可以,我想。但是当我尝试以下操作时,出现错误undefinedmethod'strftime'fornil:NilClassf.object.birth_date.strftime('%m/%d/%Y'),:size=>"20"%>根据其他一些问题/答案,我尝试了以下方法。它适用于非空值,但它是丑

ruby-on-rails - ActiveRecord 查询 : where a field is not true

我想查找某个字段不正确的所有记录。用于此的有效AR语法是:Dog.where(:stray=>[false,nil])是否有更简洁的方式来查询“nottrue”?到处都必须迎合这种mysql的细微差别,这真的很糟糕。 最佳答案 命名作用域怎么样?scope:not_stray,where("strayISNULLORstray=false")然后使用:Dog.not_stray 关于ruby-on-rails-ActiveRecord查询:whereafieldisnottrue,我们在

ruby-on-rails - Rails ActiveRecord - update_all : how to update multiple fields at once with mixed type of arguments

我有一个用例,我想使用ActiveRecord::Relationupdate_all方法并指定要设置的几个字段。我使用update_all是因为可以更新很多条目,我不想将它们全部加载并一个一个地更新。其中一些需要直接的SQLSET语句,例如因为我根据另一列的值设置一列。是否有一个简单的语法与update_all一起使它可读,沿着这个=>MyModel.where(state::foo).update_all(['timespent=timespent+500',#Can'tbeanythingelsethanaSQLstatementstate::bar,#RegularRailsS

Ruby 2.4.1 Dir.children( dirname ) 为 Dir :Class"返回 "undefined method ` children'

我是Ruby的新手,正在尝试学习它。我使用的是最新的Ruby版本(2.4.1)和交互式RubyShell。我在Dir类中遇到过children方法。我试过这个例子fromthedocumentation:Dir.children("testdir")#=>["config.h","main.rb"]但它似乎不起作用,因为我收到以下消息:undefinedmethod`children'forDir:Class我错过了什么? 最佳答案 这似乎是某种文档困惑。Dir.children方法是在Feature#11302中引入的进入Ruby