jjzjj

floating-action-button

全部标签

ruby-on-rails - 从 Controller Action 中调用/lib 中的类

嗨,我对此有点困惑。我要解决的是我在lib/目录中有一个名为ticket_pdf.rb的文件,我计划为我的应用程序生成一些发票PDF。我想调用此类的一个函数来从我的Controller操作中生成PDF。ticket_pdf.rb看起来像这样classTicketPDFdefgenerate_pdf(purchase)puts"TicketID=#{purchase.ID}"endend在Controller中我执行此操作。classCustomer::MyController当我尝试创建一个像这样的对象时,它给我一个像这样的500错误。uninitializedconstantCust

ruby-on-rails - 将 float 舍入到 Ruby 中最近的四分之一

我在RubyonRails应用程序中使用外部API。我需要向这家公司发送花车,但他们只接受1.0、1.25、1.5、1.75等值,2.0等我的值可能类似于1.34或1.80。理想情况下,我需要将它们四舍五入到最接近的0.25。完成此任务的最佳方法是什么?如果我执行1.34.round(0),它会给我1.0,这比我需要的要低。谢谢! 最佳答案 (1.27*4).round/4.0#=>1.25如果你打算经常使用它,猴子修补Float类是非常有意义的,以简化使用:classFloatdefround_to_quarter(self*4)

ruby - Float#to_d 在哪里?

有时我看到代码使用to_d。ruby文档甚至声明thereisaFloat#to_dmethod.但是,它不在我的ruby​​版本中(ruby1.9.3p263(2012-08-23revision36792)。1.9.3p263:001>"0.0".to_dNoMethodError:undefinedmethod`to_d'for"0.0":Stringfrom(irb):1from/home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in`'1.9.3p263:002>0.0.to_dNoMethodError:undefinedm

ruby-on-rails - 如何配置 action mailer(我应该注册域)?

我正在使用RubyonRails创建一个简单的非盈利应用程序。我必须设置以下设置才能使用Gmail发送电子邮件:Depot::Application.configuredoconfig.action_mailer.delivery_method=:smtpconfig.action_mailer.smtp_settings={address:"smtp.gmail.com",port:587,domain:"domain.of.sender.net",authentication:"plain",user_name:"dave",password:"secret",enable_sta

ruby - 如何在 Ruby 中将 float 舍入到指定数量的有效数字?

如果有一个等价于R'ssignif的东西就好了Ruby中的函数。例如:>>(11.11).signif(1)10>>(22.22).signif(2)22>>(3.333).signif(2)3.3>>(4.4).signif(3)4.4#It'susually4.40butthat'sOK.Rdoesnotprintthetrailing0's#becauseitreturnsthefloatdatatype.ForRubywewantthesame.>>(5.55).signif(2)5.6 最佳答案 可能有更好的方法,但这似乎

带有双 0 的 Ruby float

打印float时,ruby打印1234.0,句点后只有一个0。我如何强制ruby​​打印两个0? 最佳答案 格式化字符串来拯救:>>puts"%.2f"%1.0#=>nil1.00 关于带有双0的Rubyfloat,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5702906/

ruby-on-rails - 什么是 :domain symbol referring to when configuring action mailer?

Appname::Application.configuredoconfig.action_mailer.delivery_method=:smtp#typicalsmtp_settingsforgmailaccountconfig.action_mailer.smtp_settings={:address=>"smtp.gmail.com",:port=>587,:domain=>"domain.of.sender.net",:authentication=>"plain":user_name=>"spencecooley":password=>"secret":enable_sta

Ruby float 到字符串错误

Ruby新手。这段代码有什么问题?city_details['longitude']+","+city_details['latitude']我收到这个错误:./player_location.rb:6:in`+':Stringcan'tbecoercedintoFloat(TypeError) 最佳答案 看起来city_details['longitude']和city_details['latitude']是Float值。您不能像这样在Ruby中将Float添加到String。您可以将所有内容转换为String,然后+它们,或者

ruby - 如何比较 Floats 和 delta?

Ruby中是否有一些功能/语法来比较两个float和增量?类似于来自test/unit的assert_in_delta(expected_float,actual_float,delta)但返回bool值? 最佳答案 (expected_float-actual_float).abs 关于ruby-如何比较Floats和delta?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/

ruby-on-rails - 如何在 Ruby 中将 MS Excel 日期从 float 转换为日期格式?

尝试在ruby​​脚本中使用roogem解析XLSX文件。在Excel中,日期以DDDDD.ttttt格式存储为float或整数,从1900-01-00(00no01)开始计算。因此,为了转换诸如40396之类的日期-您将使用1900-01-00+40396,您应该得到2010-10-15,但我得到的是2010-08-08。我正在使用active_support/time进行这样的计算:Time.new("1900-01-01")+40396.days我的计算有误还是主动支持有问题?我在Windows7+最新的active_supportgem(3.2.1)上运行ruby​​1.9.3