草庐IT

action_list

全部标签

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 - 如何配置 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-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-on-rails - Ruby Net::FTP,从 ftp.list() 中提取文件名

我正在使用以下代码尝试使用Ruby从ftp获取所有文件。files=ftp.list()files.eachdo|file|ftp.gettextfile(file)end问题是ftp.list返回整行信息,而不仅仅是文件名,例如-rw-r--r--1ftpftp0May3111:18brett.txt如何从这个字符串中提取文件名?非常感谢 最佳答案 您可以使用nlst像这样的公共(public)方法files=ftp.nlst("*.zip")|ftp.nlst("*.txt")|ftp.nlst("*.xml")#optiona

ruby - FactoryGirl create_list 传入多个值

如果我有这个工厂:factory:product,class:Productdoname{Faker::Commerce.product_name}description{Faker::Lorem.paragraph}price{Faker::Number.number(3)}end我可以使用create_list创建2个这样的产品:FactoryGirl.create_list(:product,2)但我想将默认值传递给我的两个产品,我会假设理论上是这样的吗?prods=[{:name=>"Product1"},{:name=>"Product2"}]FactoryGirl.crea

ruby-on-rails - Rails 上的 ruby : How to have multiple submit buttons going to different methods (maybe with with_action? )

这个问题在这里已经有了答案:HowdoIcreatemultiplesubmitbuttonsforthesameforminRails?(7个答案)关闭9年前。所以..'save'%>'library'%>然后在我的Controller中:with_actiondo|a|a.savedoenda.librarydoendend问题是只有一个操作被调用...两个submit_tags调用相同的操作...知道为什么吗?或者我如何获得两个按钮以将表单提交给两种不同的方法?

ruby-on-rails - 如何在测试 Action 时将值放入闪存中

我正在尝试测试需要将值存储在闪存中的操作。defmy_actionifflash[:something].nil?redirect_toroot_pathifflash[:something]returnend#Dosomeotherstuffend在我的测试中,我做了类似的事情:before(:each)doflash[:something]="bob"endit"shoulddowhateverIhadcommentedoutabove"doget:my_action#Assertsomethingend我遇到的问题是flash在my_action中没有值。我猜这是因为实际上没有请

ruby - 我在 "gem list"中看到 gem 但有 "no such file to load"

我在Ubuntu10上sudoapt-getinstallruby1.9.1-full然后下载rubygem1.3.7的源码并安装sudorubysetup.rb然后,例如,安装sinatrasudogeminstallsinatra最后打开irb并输入require"rubygems"require"sinatra"得到错误LoadError:nosuchfiletoload--sinatrafrom(irb):2:in`require'from(irb):2from/usr/bin/irb:12:in`' 最佳答案 我正好遇到了

ruby-on-rails - ruby on rails 中的 Controller 和 Action 有什么区别?

谁能告诉我ruby​​onrails中Controller和Action之间的区别?我从官方Rails指南中获取了这个定义:Acontroller'spurposeistoreceivespecificrequestsfortheapplication.Routingdecideswhichcontrollerreceiveswhichrequests.Often,thereismorethanoneroutetoeachcontroller,anddifferentroutescanbeservedbydifferentactions.Eachaction'spurposeistoc

ruby-on-rails - Rails 仪表板设计 : one controller action per div

作为Rails的新手(更像是基础设施专家),我正在实现一个仪表板。仪表板将由多个页面组成,每个页面将包含多个图表/表格/等。对于模块化,我希望添加新图表或更改数据View尽可能简单。假设一页有5个不同的图表。我可以让Controller进行5次单独的数据查找,将所有相关数据保存在实例变量中,并呈现5个部分,每个部分都涉及数据的子集。但是看起来更模块化的是有一个“索引”ControllerAction,它的渲染有一堆div,并且对于每个div都有另一个ControllerAction,它进行数据查找并有一个相关的View部分负责管理该数据的View在分区内。因此,如果我要显示包含两个图表