jjzjj

image-formats

全部标签

ruby-on-rails - 如何从 format.xml 中删除 <hash></hash>

我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

ruby-on-rails - Rails - Carrierwave 进程抛出 ArgumentError : no images in this image list

在尝试实现应用auto_orient的过程之后!对于我的图片,我收到此错误:ArgumentError(noimagesinthisimagelist):app/uploaders/image_uploader.rb:36:in`fix_exif_rotation'app/controllers/posts_controller.rb:12:in`create'Carrierwave在没有进程的情况下工作正常,但在添加进程后尝试上传图像时抛出错误。流程如下:process:fix_exif_rotationdeffix_exif_rotationmanipulate!do|image|

ruby - 如何将字符串格式的毫秒数转换为 HH :MM:SS format in Ruby in under 3 lines of code?

@scores_raw.eachdo|score_raw|#belowiscodeiftimewasbeingsentinmillisecondshh=((score_raw.score.to_i)/100)/3600mm=(hh-hh.to_i)*60ss=(mm-mm.to_i)*60crumbs=[hh,mm,ss]sum=crumbs.first.to_i*3600+crumbs[1].to_i*60+crumbs.last.to_i@scoressum,:hms=>hh.round.to_s+":"+mm.round.to_s+":"+ss.round.to_s}@score

ruby-on-rails - 带有选项的 link_to image_tag (rel, title)

在HTML中我会写:但我必须针对ruby​​onrails对其进行调整,而且我对它还很陌生...所以我尝试了:rel="lightbox"title="mycaption">...但它不起作用,因为“rel="lightbox"title="mycaption">”部分未应用但出现在html部分上+我看到了2个图像,而我应该只看到“imagethumb”。我也试过:"lightbox",:title=>"mycaption")%>我也看到了这两张图...我应该怎么做才能获得与我编写的HTML代码等效的内容? 最佳答案 试试这个"")

ruby-on-rails - 如何匹配YYYY-MM-DDThh :mm:ssTZD timezone format in ruby

我想检查在ruby​​中输入的日期的iso8601格式,比如start_date="2011/05/05"应该匹配2011-05-05T00格式:00:00-04:00并相应地返回错误。我们应该在这里使用正则表达式还是为此提供任何方法? 最佳答案 听起来像你想要的Time.iso8601:require'time'iso=Time.iso8601(start_date)参见thisblogpost获取更多信息。编辑:这是一个简短但完整的有效测试程序:require'time'text="2011-05-05T00:00:00-04:

ruby - 应该 validate_format_of 。 not_with 在框架中有问题(或者在我的理解中)

我将以下代码放入RSpec测试中:it{shouldvalidate_format_of(:email).not_with('test@test')}并设置实际的类:validates:email,:presence=>true,:format=>/\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i当我运行测试时,我得到:失败:1)用户失败/错误:它{应该validate_format_of(:email).not_with('test@test')}当电子邮件设置为“test@test”时,预期错误包括“can'tbeblank”,得到错误

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 - 在 ruby​​ 中使用 matplotlib.image 是否有等效项

一直在尝试在jupyternotebook中使用Ruby。使用Python我可以做到这一点importmatplotlib.imageasmpimg有谁知道Ruby的等价物,我没能在任何iRuby或sciruby文档中找到它?澄清一点,在我的gemfile中我有这个gem'iruby'gem'cztop'gem'matplotlib'但似乎无法访问我习惯在python中使用的matplotlib的image部分。我正试图找到在Python中我会这样写的Ruby版本#importingsomeusefulpackagesimportmatplotlib.pyplotaspltimport

ruby - 是否有使用 Google Images API 的 Ruby gem?

我需要在我的Rails应用程序上与GoogleImagesAPI对话。是否有Rubygem可以做到这一点?我发现了一个使用已弃用API的旧gem。 最佳答案 有一个名为google_custom_search_api的gem,它使用较新的google自定义搜索API:https://github.com/wiseleyb/google_custom_search_api您可以通过为searchType参数指定image将其限制为图像搜索,如下所示:results=GoogleCustomSearchApi.search("poker

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"%>根据其他一些问题/答案,我尝试了以下方法。它适用于非空值,但它是丑