草庐IT

attribute_exists

全部标签

ruby - 使用 Rspec 在单元测试中测试 "accepts_nested_attributes_for"

我是Rails和测试模型的新手。我的模型类是这样的:classTester而且我想在不使用任何其他gem的情况下使用rspec对“accepts_nested_attributes_for:skill”进行测试。我怎样才能做到这一点? 最佳答案 有方便的shouldagem匹配器用于测试accepts_nested_attributes_for,但您提到您不想使用其他gem。因此,仅使用Rspec,想法是设置包含所需Tester属性的attributes散列和包含所需skill_attributes的嵌套散列技能属性;然后传入Tes

ruby - 尝试安装 pg gem : Brew bad interpreter error and not existing ruby version 时

我在重新安装ruby​​、rails、xcode等时确实犯了一些错误(甚至可能我已经删除了我的系统Ruby安装:/)这是我现在拥有的:系统:OSX10.8.2(64位)whichruby​​给我/usr/local/bin/ruby我已经安装了ruby1.9.3p286、Rails3.2.8和rvm1.16.17(stable)我已经按照以下提示安装了Ruby和Rails:http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard接下来我想运行geminstallpg但出现错误:Nosu

ruby - Stripe 连接 : Charging an existing customer against a "connected" (Standalone) account

如果试图通过connectedaccount向客户记录(具有关联的信用卡)收费,我得到一个错误声明,“没有这样的客户:cus_xxxx”——尽管当不使用“已连接”帐户(通过平台账号)。例如,考虑以下Ruby代码,假设我们有一个ID为acct_ABC123的“已连接”(独立)帐户:#Usethe(secret)APIkeyforthe"platform"orbaseaccount.Stripe.api_key='sk_[...]'customer=Stripe::Customer.create(email:'customer@example.com')#Associateacredit-

ruby-on-rails - 使用带有回形针附件的 FactoryGirl 的 attributes_for

我有一个名为Photo的模型,它有一个名为image的回形针附件。我有测试创建带附件的新照片的工作规范,并且可以手动创建它们。我在整个规范中使用了以下FactoryGirl工厂:FactoryGirl.definedofactory:photodoimage{File.new(File.join(Rails.root,'spec','fixtures','images','minimum.jpg'))}#Otherattributesomittedendend我需要使用attributes_for(:photo)生成属性以传递到PhotoController的创建操作中,但这样做会导致

ruby-on-rails - ruby rails 3 : How to access an attribute of each record in a has_many query

我不确定如何在标题中表达它,但我正在尝试执行以下操作。我有2个具有以下关系的模型:classCampaign现在,Point模型有一个“locale”属性,我希望能够将特定事件的每个点的所有“locale”放入一个数组、集合或其他任何东西中,而无需执行类似locales=Array.newcampaign.points.eachdo|p|locales我在想一些与campaign.points.locales类似的东西。是否有一些很好的Rails方法来执行此查询,或者我只需要遍历集合?感谢您的帮助。编辑:还因为这种关系实际上是一种“has_manythrough”关系,所以这种方法不起

ruby-on-rails - 炼油厂 CMS : generating migrations for existing models within an engine

我想向我在RefineryCMS引擎中创建的模型添加一个属性。我知道我可以执行以下操作:rails生成迁移AddPartNumberToProductspart_number:string手动将迁移文件从db/migrate移动到vendor/extensions/products/db/migrate但是是否有命令首先将迁移生成到正确的文件夹中?谢谢! 最佳答案 根据@parndt(theleaddeveloperoftheRefineryproject),我上面概述的方法是正确的。

ruby - 使用 Ruby 和 Savon 的 SOAP 客户端 : How to add EncodingType attribute in Nonce element

我需要创建一个ruby​​web服务客户端(使用Savon)来对需要Nonce中的EncodingType的web服务进行soap调用。所以正确的soap消息将具有这样的Nonce元素:......SomeHashValue......但是在我的Savon客户端中,我不知道如何在Nonce元素中添加该属性。我的代码在这里:......client=Savon.clientdowsdl.endpoint="http://webservicehost/TestWebService"wsdl.namespace="namespace"wsse.credentials"username","p

ruby - 野切 : List attributes name and value?

我想解析我的XML文件。我需要计算属性并获得它们的名称和值...require'nokogiri'f=File.open("file.xml")doc=Nokogiri::XML(f)f.closepdoc.xpath("/a/@*").count我想要属性列表。我试过了:doc.attributes.eachdo|name,attr|pname=>attr.valueend但是错误:in`':undefinedmethod`attributes'for#(NoMethodError)我不知道为什么...Blabla或者我希望能够有名字。喜欢:putsdoc.xpath("/a/@*"

ruby-on-rails - 使用 add_foreign_key : 'column "user_id"referenced in foreign key constraint does not exist' 进行 Rails 迁移

(Rails是5.0.0版本,Ruby是2.3.0p0)我想在我的用户表和卡片表之间创建关联。我已将belongs_to:user添加到Cards模型,并将has_many:cards添加到Users模型,并创建了一个迁移:classAddUserIdToCard当我运行rakedb:migrate时,我收到错误:ActiveRecord::StatementInvalid:PG::UndefinedColumn:ERROR:column"user_id"referencedinforeignkeyconstraintdoesnotexist:ALTERTABLE"cards"ADDC

ruby-on-rails - Active Record 未定义方法 read_attribute_for_serialization

我有一个Rails范围,它获取表的第一条记录并将其分配给@variable。它返回单个对象或空的事件记录关系。我的问题是我正在使用自定义序列化程序来呈现json,但是如果范围返回一个空的ActiveRecord关系,我会得到“ActiveRecord未定义方法read_attribute_for_serialization”,除非我使用each_serializer,但是如果范围返回一个我有的对象使用序列化器渲染它:有没有办法不这样做就解决这个问题:if@variable.blank?renderjson:@variable,each_serializer:CustomSerializ