jjzjj

public-activity

全部标签

ruby - 时间 :Class after requiring active_support/time_with_zone 的未定义方法 `zone`

我在使用Ruby2.2.1并安装了active_support4.2,所以我想使用Time.zone.parse('2007-02-1015:30:45')如此处所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html但即使在需要active_support和active_support/time_with_zone之后,我觉得Time.zone仍然不起作用。观察:2.2.1:002>require"active_support"=>true2.2.1:003>Time.zoneNoMethodError

ruby - 如何在 ruby​​ on rails 应用程序中指定公共(public)目录的路径?

我想解析public文件夹中的.csv文件,我试过/../的,#{RAILS_ROOT}/public但没有成功(没有这样的文件或目录错误)。我不知道如何使用Rails.public_path(Rails.public_path/filename.csv不起作用)请帮助 最佳答案 您可以访问Rails.root路径,使用它来获取路径Rails.root.join("public","filename.csv")您可能需要调用to_s,具体取决于您希望如何使用结果(作为Path对象或作为字符串)。

ruby-on-rails - 为什么都是autoload,load_all!并要求全部用于 active_support.rb?

我正在查看active_support.rb以尝试了解它使用的加载过程。它使用三种加载方法:load_all!、autoload和require。为什么在同一个文件中使用三种不同的加载方式?moduleActiveSupportdefself.load_all![Dependencies,Deprecation,Gzip,MessageVerifier,Multibyte,SecureRandom,TimeWithZone]endautoload:BacktraceCleaner,'active_support/backtrace_cleaner'autoload:Base64,'ac

ruby - 使用 RVM 使用 sinatra 应用程序加载 Active Record gem 时出错

我为我正在启动的sinatra应用程序设置了一个项目级RVMgemset,它将使用ActiveRecord连接到本地数据库。为了测试它,我尝试运行以下测试应用程序:测试.rbrequire'rubygems'#maynotbeneeded,dependingonplatformrequire'sinatra'require'activerecord'classArticle"sqlite3",:database=>"hw.db")Test.first.contentend(摘自这个问题的答案:What'sthebestwaytotalktoadatabasewhileusingSina

ruby-on-rails - 将 ACL 设置为 public_read 的文件上传到 AWS S3

在我的Rails应用中,我在创建时将客户RMA运输标签保存到S3存储桶中。我刚刚更新到aws-sdkgem的V2,现在我设置ACL的代码不起作用。在V1.X中有效的代码:#SaveslabeltoS3buckets3=AWS::S3.newobj=s3.buckets[ENV['S3_BUCKET_NAME']].objects["#{shippinglabel_filename}"]obj.write(open(label.label('pdf').postage_label.label_pdf_url,'rb'),:acl=>:public_read).write似乎已被弃用,所以

ruby-on-rails - 如何获取 Active Storage 图像的 url

我想通过api获取带有附加图像的记录列表作为链接或文件。我有一个简单的模型:classCategory下一步行动:defindex@categories=Category.all.with_attached_imagerenderjson:@categories.to_json(include:{image_attachment:{include::blob}})end这是我获得图像对象的唯一方法。我看到下一个结果:{"id":4,"name":"Cat1","description":""},{"id":1,"name":"Cat2","description":"","image_

ruby - 您如何处理 Active Admin 资源中的序列化编辑字段?

我有一个模型,Domain,它有一个文本字段,names。>railsgmodelDomainnames:textinvokeactive_recordcreatedb/migrate/20111117233221_create_domains.rbcreateapp/models/domain.rb>rakedb:migrate==CreateDomains:migrating==================================================--create_table(:domains)->0.0015s==CreateDomains:migrat

ruby - 配置Active Admin的标签has_many

好吧,我有两个与一对多关联相关的模型。#models/outline.rbclassOutlinetruef.input:pages,:required=>true...f.buttonsendf.inputs"DocumentVersions"dof.has_many:documents,:name=>"DocumentVersions"do|d|d.input:file,:as=>:filed.buttonsdod.commit_button:title=>"AddnewDocumentVersion"endendendendend正如您在admin/outlines.rb中看到的

ruby-on-rails - attr_accessible 在 rails Active Record 中

当我使用attr_accessible指定我将公开模型中的哪些字段时,脚本/控制台也是如此吗?我的意思是我没有指定为attr_accessible的东西也不能通过控制台访问? 最佳答案 这仅适用于批量分配。例如,如果您要在模型中设置attr_protected:protected:>>Person.new(:protected=>"test")=>#相反,您可以使用attr_accessible将您想要的所有属性设置为可访问。但是,以下内容仍然有效:>>person=Person.new=>#>>person.protected="

ruby - 在 ruby​​ 上,为什么 include 是私有(private)的而 extend 是公共(public)的?

在ruby上,为什么include是private,而Object#extend是public? 最佳答案 Object#extend必须是公开的,否则您将无法使用它。毕竟,它的目的是将模块混合到对象中,因此您通常会像obj.extend(Foo)那样调用它,这对于私有(private)方法是不可能的。Module#include通常只在模块体内使用,如下所示:classBarincludeFooend即它通常在没有接收者的情况下被调用,所以它不必公开。当然,它也必须是私有(private)的。我猜它之所以是私有(private)的