草庐IT

has_is_baz

全部标签

ruby-on-rails - 无法在 Rails 3 中找到 has_many 的逆关联

我有以下模型:classBusiness:businesshas_many:payments,:inverse_of=>:businessendclassCustomer:customerhas_many:payments,:inverse_of=>:customerendclassPayment:paymentbelongs_to:business,:inverse_of=>:paymentend执行business.customers效果很好。但是,当我执行business.payments时,出现错误:Couldnotfindtheinverseassociationforbus

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

ruby - Rubocop 错误 'Class definition is too long ruby'

我收到rubocop错误“类定义太长。[236/100]'。我的类(class)如下所示:classSomeClassNameincludeHelperModuleattr_accessor:aaa,:bbb,:ccc....methods.....end可能会出现什么问题?rubocop文档ClassLength说“一个类(class)的长度超过了某个最大值”。什么意思? 最佳答案 是的,这是因为rubucop认为整体线路太多。我同意类(class)不应该太长,但认为最终应该由以下因素决定:类(class)是否有单一职责,方法是否

ruby-on-rails - Mac OS X 山狮 "Rails is not currently installed on this system."

我正在全新安装OSXMountainLion。我通过以下方式安装了Rails:sudogeminstallrails一切似乎都安装正确,但是当我键入rails命令(railss、rails-v等)时,我收到此错误:Railsisnotcurrentlyinstalledonthissystem.Togetthelatestversion,simplytype:$sudogeminstallrailsYoucanthenrerunyour"rails"command.'whichrails'的结果是/usr/bin/rails我认为这是一个路径问题,也许是,但我可以看到/usr/bin是

ruby - RVM + Zsh "RVM is not a function, selecting rubies with ' rvm 使用.. .' will not work"

首先我要说我不是命令行专家,所以我真的几乎不知道自己在做什么。我无法让RVM和oh-my-zsh一起玩得很好。我尝试了几种不同的解决方案,其中一些是在SO上发布的,但我发现似乎没有任何解决方案可以解决问题。最初,其他人在我的机器上安装了RVM。后来我自己设置了oh-my-zsh,记得当时遇到了很多麻烦。除了这两行,我的.zhsrc文件是完全默认的exportPATH=$HOME/bin:/usr/local/bin:/usr/local/rvm/bin:$PATH#prettysurethislinedoesnothing,althoughI'veseenthisfixaround#s

ruby-on-rails - 自定义 rails has_many 关联(通过 pg 数组)

所以基本上我想知道是否有一些通用方法来定义自己的关联类型。一些细节:我有一个模型conversations有一个PG数组列user_ids.因此,要检索我需要运行的用户对话:selectconversations.*fromconversationswhereUSER_ID=ANY(conversations.user_ids)自finder_sql它的friend现在已被弃用,我真的很想知道实现这个伪has_many关联的最佳方法是什么?目前我只使用如下方法:defconversationsConversation.where("#{id}=ANY(conversations.use

ruby-on-rails - salt 如何在 Rails 的 has_secure_password 中工作

据我所知,为了使加密密码更安全,我会生成一个随机数(盐)并将其与散列密码一起存储在用户记录中(例如。)我会连接盐使用明文密码,然后对其进行加密(哈希)。生成的哈希将更难破解。将重复此过程以验证密码。查看has_secure_password和bcrypt_ruby(披露:我不是安全专家)我不知道这是如何完成的,因为用户记录中唯一存储的是散列密码。盐在哪里? 最佳答案 密码哈希和盐保存在数据库中名为password_digest的字符串列中。看这个question. 关于ruby-on-r

ruby-on-rails - has_many 和 belongs_to 协会在 factory_girl

我有这些模型,我正在尝试创建工厂以使用factory_girl。classFoo我不确定如何在不创建工厂无休止地相互调用的循环的情况下创建工厂。Factory.define:foodo|f|f.after_createdo|ff|ff.baz=Factory(:baz)endendFactory.define:bazdo|f|f.after_createdo|ff|ff.foos=[Factory.create(:foo)]endend我意识到我可以在baz工厂中省略ff.foos=[Factory.create(:foo)],但是在我的baz中测试我被迫使用foo.baz而不是仅仅使

ruby 公案 : test_nil_is_an_object

我最近尝试使用这个工具来提高我的Rails技能:http://github.com/edgecase/ruby_koans但我无法通过一些测试。此外,我不确定我是否正确地做了一些事情,因为目标只是通过测试,有很多方法可以通过它,我可能正在做一些不符合标准的事情。有没有办法确认我做的事情是否正确?具体例子:在about_nil中,deftest_nil_is_an_objectassert_equal__,nil.is_a?(Object),"UnlikeNULLinotherlanguages"end它是告诉我检查第二个子句是否等于一个对象(所以我可以说nil是一个对象)或者只是把as

ruby - 安装 ruby​​racer 时出现错误 "invalid gem: package is corrupt"

尝试在OSX10.9上安装therubyracer时,使用以下命令:$geminstalltherubyracer-v'0.12.0'我得到错误:ERROR:Errorinstallingtherubyracer:invalidgem:packageiscorrupt,exceptionwhileverifying:undefinedmethod`path2class'for#(NoMethodError)in/Users/doved/.rvm/gems/ruby-2.0.0-p353/cache/therubyracer-0.12.0.gemXCode开发者工具已安装,我已尝试删除缓