草庐IT

update-database

全部标签

ruby-on-rails - 将 bool 值传递给 update_attributes 的问题

我有以下模型:classGuestCateringtruevalidates:order_number,:presence=>truevalidates:orderable,:presence=>trueend但是当我尝试使用以下代码更新现有的GuestCatering时:guest_catering.update_attributes(:orderable=>false)guestcatering变量是一个有效的GuestCatering对象。guest_catering对象更新后出现错误,像这样:nil}>但是当我传递一个orderable=>true时,一切都很好,没有错误。这里

ruby-on-rails - rake Assets :precompile attempting to connect to database

我正在尝试调试为什么我的应用程序在我运行rakeassets:precompile--trace时尝试连接到我的数据库。我可能在堆栈跟踪中遗漏了一些东西...有人看到相关行吗?DEPRECATIONWARNING:TheInstanceMethodsmoduleinsideActiveSupport::Concernwillbenolongerincludedautomatically.PleasedefineinstancemethodsdirectlyinActionController::Baseinstead.(calledfromat/Users/Kyle/Desktop/s

ruby-on-rails - rails : Serializing objects in a database?

我正在寻找有关在数据库中序列化对象的一些一般指导。什么是序列化对象?在数据库中序列化对象的一些最佳实践场景是什么?在数据库中创建列时使用哪些属性以便使用序列化对象?如何保存序列化对象?以及如何访问序列化对象及其属性?(使用哈希?) 最佳答案 Incomputerscience,inthecontextofdatastorageandtransmission,serializationistheprocessofconvertingadatastructureorobjectintoasequenceofbitssothatitcan

ruby-on-rails - rails : Postgres permission denied to create database on rake db:create:all

我正在尝试创建用于开发和测试的postgres数据库。我正在使用:OSX优胜美地Rails版本:4.2.0git版本:2.2.2psql版本:9.4.0ruby版本:2.1.0p0自制软件版本:0.9.5gem文件:gem'pg'数据库.yml:default:&defaultadapter:postgresqlencoding:unicodepool:5development:rakedb:create:all返回PG::InsufficientPrivilege:ERROR:permissiondeniedtocreatedatabase:CREATEDATABASE"myapp_

ruby - bundler 能告诉我 Gemfile 中的哪些 gems 有更新的版本吗(例如 bundle update 的试运行)

有没有办法运行bundleupdate在假装模式下,类似于Rails生成器的-p(假装)标志或cap的-n(试运行)标志?我在想像这样的事情:$>bundleupdate-pFetchingsourceindexforhttp://rubygems.org/Thefollowinggemshaveupdatedversions:...listofgems... 最佳答案 Bundler1.1引入了一个新的“过时”功能,这正是我一直在寻找的。PatShaughnessy很棒write-up关于新功能。用他的话说,bundleoutda

ruby-on-rails - 如何在不触及 updated_at 属性的情况下更新单个属性?

我怎样才能做到这一点?试图创建2个方法,称为defdisable_timestampsActiveRecord::Base.record_timestamps=falseenddefenable_timestampsActiveRecord::Base.record_timestamps=trueend和更新方法本身:defincrement_pagehitupdate_attribute(:pagehit,pagehit+1)end使用如下回调打开和关闭时间戳:before_update:disable_timestamps,:only=>:increment_pagehitafte

ruby-on-rails - 用于 postgresql 的 Ruby on Rails : How can I edit database. yml?

Rails新应用。当前的database.yml是这样的:#SQLiteversion3.x#geminstallsqlite3##EnsuretheSQLite3gemisdefinedinyourGemfile#gem'sqlite3'development:adapter:sqlite3database:db/development.sqlite3pool:5timeout:5000#Warning:Thedatabasedefinedas"test"willbeerasedand#re-generatedfromyourdevelopmentdatabasewhenyourun

ruby-on-rails - rails : An elegant way to display a message when there are no elements in database

我意识到我正在编写很多与此类似的代码:Youhavenomessages.Ruby和/或Rails中是否有任何构造可以让我跳过它第一个条件?那么当迭代器/循环一次都不会进入时会执行吗?为了示例:Youhavenomessages. 最佳答案 你也可以这样写:Youhavenomessages. 关于ruby-on-rails-rails:Anelegantwaytodisplayamessagewhentherearenoelementsindatabase,我们在StackOverfl

ruby-on-rails - rails : Update model attribute without invoking callbacks

我有一个具有:credits属性的用户模型。我想要一个简单的按钮,它将通过名为“add”的路由将5添加到用户的积分中,以便/users/3/add将5添加到用户id=3的积分中。defadd@user=User.find(params[:id])@user.credits+=5redirect_toroot_pathend那是我Controller的相关部分。问题是,我不想调用@user.save,因为我有一个before_save回调,它根据当前的UTC时间重新加密用户的密码。我只想简单的给属性加5,避免回调,没想到这么简单的事情这么难。编辑:我将回调更改为:before_creat

ruby-on-rails - rails 4 : How to reset test database?

我在使用Rails4并注意到我的一些RSpec测试失败了,因为我的一些测试重构使用了前置过滤器(大概是因为事务)。这篇文章描述了一个类似的问题:railstestdatabasenotclearingaftersomeruns代替使用DatabaseCleanergem,是否有清除测试数据库的rake命令?我相信rakedb:test:prepare在Rails4中被弃用了。此外,如果在交易之前,如`post:create,user:Fabricate.attributes_for(:user)`是持久性的,是否有另一种重构方式来避免手动清除测试数据库的需要?