草庐IT

Update-Upsert

全部标签

ruby-on-rails - 验证器 before_update(ing) 一个模型

我想在编辑模型时执行一些验证,所以我认为最好的方法是使用before_update在Rails中。有人可以提供使用before_update调用的自定义验证器的示例吗?例如:我有一个主题类,我只想允许主题的创建者能够更改标题。 最佳答案 #Topic.rbbefore_update:your_custom_validationprivatedefyour_custom_validation#yourcodeend您可以使用任何回调来做到这一点。也就是说,指定过滤器并将其传递给您的方法名称的符号。您可能还想考虑添加一个用户身份验证ge

ruby - 运行错误 'requirements_osx_brew_update_system ' ,

当我尝试$rvmrequirements我得到了错误:如何从此恢复(Macosx10.7)Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_system',pleaseread/Users/HARSHA/.rvm/log/1380096954/update_system.logRequirementsinstallationfailedwithstatus:1.HARSHA:~HARSHA$rvmre

ruby-on-rails - 当我执行 "bundle update"时,我从不在我的 gemfile 中的 gem 收到错误。我如何忽略这种依赖?

我正在处理一个使用twitter-bootstrap-rails的项目。这个项目建立在Linux机器上,并使用therubyracer作为javascript运行时。我一直遇到问题,因为therubyracer似乎与Windows不兼容。therubyracergemonwindows现在我正在尝试“捆绑更新”;“therubyracer”令人窒息。我想我应该可以依靠JScript。我如何告诉bundler忽略它,而不深入研究每个gem并手动删除它对therubyracer的依赖?似乎bootstrap,或者至少twitter-bootstrap-rails,取决于ruby​​race

ruby-on-rails - 如何查找 ActiveRecord::Base.update 的文档?

在Ruby/Railsapi中查找方法文档的过程是什么http://api.rubyonrails.org/.让我们以方法ActiveRecord::Base.update为例。它用于其中一个railscasts。类的api文档中没有提到更新http://api.rubyonrails.org/classes/ActiveRecord/Base.html有Base的源代码中没有关于update方法的信息https://github.com/rails/rails/blob/0065f378262dc3f47880ce6211c7474bc7d11f0b/activerecord/lib

sql - 使用 Sequel,我可以创建带有 FROM 子句的 UPDATE 语句吗

使用Sequel我想创建一个如下所示的UPDATE语句(来自Postgresdocs)UPDATEemployeesSETsales_count=sales_count+1FROMaccountsWHEREaccounts.name='AcmeCorporation'ANDemployees.id=accounts.sales_person;但是,查看Sequeldocumentation目前尚不清楚在哪里可以创建FROM子句。有办法吗?谢谢! 最佳答案 好的,BenLee的回答让我朝着正确的方向前进。解决方案:DB[:employ

ruby - ruby < 2.3 的 `gem update --system` 是否损坏?

rubygems-update升级后的今天ruby早于2.3的gemupdate--system已经开始永久失败并出现下一个错误:#gemupdate--systemUpdatingrubygems-updateFetching:rubygems-update-3.0.0.gem(100%)ERROR:Errorinstallingrubygems-update:rubygems-updaterequiresRubyversion>=2.3.0.ERROR:Whileexecutinggem...(Errno::ENOENT)Nosuchfileordirectory@dir_chdi

ruby - Rails update_all 与 hstore

使用activerecord使用hstore列更新多条记录的好方法是什么?现在我正在像这样循环、更新和保存:time=Time.now.to_sscoped_tasks.eachdo|task|task.data[:last_checked]=timetask.save!end有什么方法可以用update_all查询来做到这一点吗?我见过的一种解决方案如下所示:MyModel.update_all(:properties=>ActiveRecord::Coders::Hstore.dump({'a'=>1}))但这样做的问题是它会覆盖整个列,因此其他值会丢失。我也看到了这个:MyMod

ruby-on-rails - Rails - update_column 和 ActiveRecord 枚举

我需要在我的Rails应用程序中使用update_column来防止运行回调。我有带枚举的ActiveRecord模型:classCar在正常情况下(即当我确实希望回调运行时)我可以使用类似的东西:@car.update_attribute:state,:not_used是否可以用update_column做类似的事情?我正在使用Rails4.2 最佳答案 update_column不将符号识别为枚举的变体。我认为您必须使用Car.states[:not_used]而不是:not_used。像这样:@car.update_colum

ruby-on-rails - Rails 4 错误:ActionController::ParameterMissing in UsersController#update,找不到参数:用户

我有一个带有标准CRUD方法的用户Controller。其中一种方法是更新。defupdateif@user.update(user_params)redirect_to@user,notice:"AccountSuccessfullyupdated"elserender:editendend然后我有了rails4strongparams方法:privatedefuser_paramsparams.require(:user).permit(:name,:email,:password,:password_confirmation,:role_ids=>[])end我的观点是这样的::

ruby-on-rails - Rails 低级缓存 : Update cache when ActiveRecord object updated_at changes OR when a new object is added to collection

Rails附带片段缓存和低级缓存。片段缓存的工作原理非常清楚:Railswillwriteanewcacheentrywithauniquekey.Ifthevalueofupdated_athaschanged,anewkeywillbegenerated.ThenRailswillwriteanewcachetothatkey,andtheoldcachewrittentotheoldkeywillneverbeusedagain.Thisiscalledkey-basedexpiration.Cachefragmentswillalsobeexpiredwhentheviewfr