草庐IT

using-transactions-for-unit-tests

全部标签

ruby-on-rails - Rails 3 安装错误 : "invalid value for @cert_chain"

我正在尝试在一台新的OSXSnowLeopard机器(安装了开发工具)上安装Rails3,当我sudogeminstallrails时,我收到以下错误:ERROR:Whileexecutinggem...(Gem::FormatException)builder-2.1.2hasaninvalidvaluefor@cert_chain更新失败。有没有人见过这个?我grep为“cert_chain”编辑了builder-2.1.2目录,但找不到任何线索。Ruby版本是1.8.7OSX10.6.6谢谢! 最佳答案 这是Rubygems1

ruby-on-rails - ruby rails : provide vs content_for

我今天遇到了View辅助函数“provide”。通过查看它的手册,我仍然对它与“content_for”的不同之处感到困惑。provide(name,content=nil,&block)Thesameascontent_forbutwhenusedwithstreamingflushesstraightbacktothelayout.Inotherwords,ifyouwanttoconcatenateseveraltimestothesamebufferwhenrenderingagiventemplate,youshouldusecontent_for,ifnot,useprov

ruby-on-rails - rails : How to use dependent: :destroy in rails?

我有2个模型,如下所述。classEmpGroup和classEmpGroupMember现在的问题是,每当我试图摧毁一个组时,我都会收到如下错误。PG::ForeignKeyViolation:ERROR:updateordeleteontable"emp_groups"violatesforeignkeyconstraint"fk_rails_bd68440021"ontable"emp_group_members"DETAIL:Key(id)=(1)isstillreferencedfromtable"emp_group_members".我错过了什么?

ruby-on-rails - Rails 测试找不到 test_helper

我试图通过ruby​​test/unit/mytest.rb运行单独的测试,但我总是收到“没有这样的文件要加载-test_helper”的错误。Google提出了一些建议,但没有一个对我有用。我在Ubuntu10.10上运行Rails3.0、Ruby1.9.2(通过RVM)这是我到目前为止所做的尝试-非常感谢任何建议将“requiretest_helper”更改为“requireFile.dirname(FILE)+“/../test_helper””在test/unit/mytest_test.rb中。它带回“没有要加载的文件--test/unit/../test_helper”尝试

ruby-on-rails - rails erb 表单助手 options_for_select :selected

我在erb中有一个编辑表单。在代码中我有一个带有选项的选择::gender)%>但是,选择没有显示正确的选择值。我做错了什么?如果我对其进行硬编码,我可以让它工作,但这当然不是一个可行的选择。 最佳答案 在您的代码中,您的options_for_select()调用将所选值设置为“性别”,并且不会尝试使用表单对象中的值。请参阅options_for_select()的文档用于使用示例。options_for_select(['Mare','Stallion','Gelding'],f.object.gender)options_fo

ruby-on-rails -/usr/bin/env ruby​​ 没有这样的文件或目录 : Using capistrano 3, capistrano/rbenv、capistrano/bundler 和 capistrano/rails(使用 rails 4)

我正在使用capistrano、capistrano/rbenv、capistrano/bundler和capistrano/rails。我在capistrano编译Assets的步骤中得到这个错误:DEBUG[49a50df6]/usr/bin/env:DEBUG[49a50df6]rubyDEBUG[49a50df6]:NosuchfileordirectoryDEBUG[49a50df6]在生产服务器中/usr/bin/envruby​​-v是正确的。我知道这一点:why-does-something-work-in-my-ssh-session-but-not-in-capis

ruby-on-rails - minitest、test::unit 和 rails

我在某处读到“minitest”是“ruby1.9.2+的新测试::单元”。但ruby​​1.9.3似乎包含两者test::unit和minitest,是真的吗?在默认的rails测试中,如Railstestingguide中所述....诸如ActiveSupport::TestCase、ActionController::TestCase之类的东西,是使用Test::Unit还是Minitest?在Rails指南中,它显示了带有如下定义的测试的示例:test"shouldshowpost"doget:show,:id=>@post.idassert_response:successe

ruby-on-rails - rails : getting data from a table for each iteraction of a loop

我有一个循环(针对@dataset中的项目),我希望在每次迭代中从另一个表中获取不同的数据并进行一些将在View中打印的操作。我无法从循环中使用的数据集中获取此数据。如何根据MVC执行此操作?我可以将代码放入循环中,在View中,但我认为这太可怕了。我必须使用助手来执行此操作,并从View中调用该函数吗? 最佳答案 如果你有一个表,想从另一个表中获取数据,通常是在has_many关系的情况下。例如,我们有@people(Person模型),每个人都有has_many地址(Address模型)。在这些情况下,最好的办法就是这样做#Co

ruby-on-rails - 获取 fields_for 和 accepts_nested_attributes_for 以处理 belongs_to 关系

我似乎无法使用Rails2.3的新accepts_nested_attributes_for工具在RailsView中为belongs_to关系生成嵌套表单。我确实检查了许多可用的资源,看起来我的代码应该可以工作,但是fields_for对我来说是爆炸性的,我怀疑它与如何做有关我配置了嵌套模型。我遇到的错误是一个常见的错误,可能有多种原因:'@account[owner]'isnotallowedasaninstancevariablename下面是涉及的两个模型:classAccount'User',:foreign_key=>'owner_id'accepts_nested_att

ruby-on-rails - accepts_nested_attributes_for rails 4 没有删除

我已经阅读和研究了大约3天。这是我最后的选择。土地.rb:has_many:uploads,:dependent=>:destroyaccepts_nested_attributes_for:uploads,:allow_destroy=>true,:reject_if=>:all_blank上传.rbbelongs_to:land_land_form_partial.html.erb{:multipart=>true}do|f|%>Delete:#...buttonsandotherfieldslands_controller.rbdefupdateif@land.update_at