草庐IT

CLASS_NAME

全部标签

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 型号 : Name -- First, 最后

我是Rails的新手,正在为用户开发一个带有Profile模型的Rails3应用。在配置文件模型中,我希望有一个“名称”条目,并且我希望能够使用简单的语法访问它的逻辑变体,例如:user.profile.name="JohnDoe"user.profile.name.first="John"user.profile.name.last="Doe"这可能吗,还是我需要坚持使用“first_name”和“last_name”作为我在这个模型中的字段? 最佳答案 有可能,但我不推荐。如果我是你,我会坚持使用first_name和last_

ruby-on-rails - AASM 不适用于我的 rails 3 和 ruby​​ 1.8.7(未定义方法 `name' 为 nil :NilClass )

我正在使用Rails3.2.2,带有aasmgem,我有这样的Document模型:classDocumenttruestate:readstate:closedevent:viewdotransitions:to=>:read,:from=>[:unread]endevent:closedotransitions:to=>:closed,:from=>[:read,:unread]endend现在在我的控制台上:➜✗bundleexecrailscLoadingdevelopmentenvironment(Rails3.2.2)irb(main):006:0>Document.cre

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

ruby-on-rails - rails : How do I autocomplete search for Name but save ID?

我用过这个视频http://railscasts.com/episodes/102-auto-complete-association-revised在我的应用程序的表单中设置自动完成搜索输入。(该视频可能仅供成员(member)使用,因此我也会发布我的代码。本质上,它会搜索数据库(名称)的一列,并在您键入时在下拉列表中自动完成。这一切都很好,但是,我想要什么表单要做的是提交与名称相关的ID,而不是名称本身。我假设没有简单的方法可以仅在View中执行此操作。任何帮助都会很棒。下面的代码,让我知道是否有任何其他代码有帮助。谢谢Controller:defgame_namegame.try

ruby - Ruby 中 lambda 和 def method_name 的区别

我正在阅读Pickaxe1.9,作者是这样使用lambda的:bo=lambda{|param|puts"Youcalledmewith#{param}"}bo.call99=>'Youcalledmewith99'bo.call"cat"=>'Youcalledmewithcat'我的问题是:这与仅定义一个执行相同操作的方法相比有何更好/更差/不同之处?像这样:defbo(param)puts"Youcalledmewith#{param}"endbo("hello")=>'Youcalledmewithhello'对我来说,lambda语法似乎更令人困惑,更像意大利面条。