草庐IT

new-style-class

全部标签

ruby-on-rails - 如何修复 `new' :String 的未定义方法 "Rack::Cors"

我是RubyonRails的新手,正在学习如何使用Angular,但是在我运行“geminstallrack-cors”之后,当我尝试启动Rails应用程序时,我保持收到此错误:C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/actionpack-5.1.1/lib/action_dispatch/middleware/stack.rb:35:in`build':undefinedmethod`new'for"Rack::Cors":String(NoMethodError)Didyoumean?nextfromC:/Ruby23-x64/lib/ruby

ruby-on-rails - Resque 和 New 遗物

我开始在使用NewRelic和resque时遇到奇怪的错误INFO:StartingAgentshutdownERROR:undefinedmethod`write'fornil:NilClass:Unabletosenddatatoparentprocess,pleaseseehttps://newrelic.com/docs/ruby/resque-instrumentationformoreinformation我已按照说明进行操作here我也不再在我的新遗物控制面板中看到任何东西 最佳答案 directions最近已更新。我

ruby - 导轨 3.2.x : how to reload app/classes dir during development?

我有一些Rails代码不适合模型或Controller盒。所以根据thisanswer,我创建了一个app/classes目录。Rails3似乎自动将其添加到Rails中的“加载路径”,我的应用程序正确地找到了我在其中定义的类,而无需使用require语句。但是app/classes中的代码不会在开发模式下重新加载;如果我进行了更改,我需要重新启动服务器才能看到该更改。在Rails3.2.x中使给定目录“可重新加载”的正确方法是什么?这里的一些答案建议这样做:config.autoload_paths+=%W(#{config.root}/app/classes)但我相信这仅具有将ap

ruby - class << self 是什么意思?

关于:classTestclass我脑海中浮现出如下画面:因为在Ruby中一切都是对象,类本身就是类Class的对象。.调用class你打开ClassTest内部的定义并注入(inject)一些实例方法。自Test是Class的实例,您可以像在对象上调用实例方法一样调用这些方法:Test.hi.以下是有助于可视化我之前句子的伪代码:classClassdefhiputs“Hithere”endendTest=Class.new(classTestend)Test.hi我做对了吗? 最佳答案 假设我们有一个对象obj类A.此时,obj

ruby - 在 define_method 中调用 super 时没有父类(super class)方法

当我重写一个已经存在的方法时,为什么会出现以下错误talk:super:nosuperclassmethodtalk(NoMethodError)?如何修复此代码以调用super方法?这是我正在使用的示例代码classFoodeftalk(who,what,where)p"#{who}is#{what}at#{where}"endendFoo.new.talk("monster","jumping","home")classFoodefine_method(:talk)do|*params|super(*params)endendFoo.new.talk("monster","jump

ruby - 使用 ruby​​ 生成格式化为/etc/shadow 的 SHA512 crypt-style 哈希?

我想生成SHA512散列密码以直接包含在/etc/shadow文件中以与chef'suserresource一起使用.通常我会为此访问stdlib的Digest库,但它不会以正确的格式生成哈希:ruby-1.9.2-p136:001>require'digest/sha2'=>trueruby-1.9.2-p136:002>Digest::SHA512.hexdigest('test')=>"ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b1437

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 - wicked_pdf : footer height/styling

我正在使用很棒的wicked_pdfgem生成PDF,但我不知道如何更改页脚中的某些样式。我有一个用于页脚的HAML模板,大致如下所示:!!!%html%head%meta{:charset=>"utf-8"}=wicked_pdf_stylesheet_link_tag"pdf"%body.footer%pLine1%pLine2%pLine3还有一些样式:.footer{padding-top:1em;border-top:1pxsolid#ccc;}样式应用得很好,但由于页脚高度较小,只有第一行可见。我试过通过CSS设置高度,但到目前为止还没有。如果我使用例如center、att

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