草庐IT

dynamic-update

全部标签

ruby-on-rails - 不选择 updated_at 属性就无法在 Rails 4 中更新模型

我正在从Rails3.2.13升级到4,在更新模型时遇到了问题。我正在尝试更新只有id的模型上的单个属性,我还想要验证和回调。这在Rails3中运行良好,但我在Rails4中遇到了问题。如果我这样做,在rails4中:user=User.select(:id).firstuser.first_name='name'user.save!我得到错误:NoMethodError:undefinedmethod`type_cast'fornil:NilClassfromC:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activereco

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

c++ - 为什么参数依赖查找不适用于函数模板 dynamic_pointer_cast

考虑以下C++程序:#includestructA{};structB:A{};intmain(){autox=std::make_shared();if(autop=dynamic_pointer_cast(x));}使用MSVC2010编译时,出现以下错误:errorC2065:'dynamic_pointer_cast':undeclaredidentifier如果auto,错误仍然存​​在替换为std::shared_ptr.当我完全符合std::dynamic_pointer_cast的通话条件时,程序编译成功。另外,gcc4.5.1也不喜欢:error:'dynamic_p

c++ - 为什么参数依赖查找不适用于函数模板 dynamic_pointer_cast

考虑以下C++程序:#includestructA{};structB:A{};intmain(){autox=std::make_shared();if(autop=dynamic_pointer_cast(x));}使用MSVC2010编译时,出现以下错误:errorC2065:'dynamic_pointer_cast':undeclaredidentifier如果auto,错误仍然存​​在替换为std::shared_ptr.当我完全符合std::dynamic_pointer_cast的通话条件时,程序编译成功。另外,gcc4.5.1也不喜欢:error:'dynamic_p

ruby-on-rails - 添加订单详细信息 Microsoft Dynamics CRM Online API

我正在使用以下gem连接到MicrosoftDynamicsCRM:https://github.com/TinderBox/dynamics_crm.我能够很好地连接和添加联系人、潜在客户和其他一些东西。我的问题是,我不知道如何添加订单和订单详细信息。这是我用来创建订单详细信息的代码:details=Hash.newdetails={'quantity'=>1000.0,'productid'=>product,'salesorderid'=>DynamicsCRM::XML::EntityReference.new("salesorder",order.id),'uomid'=>D

ruby-on-rails - RoR - Model.all,但没有 created_at 和 updated_at 字段

这个问题在这里已经有了答案:Rails4-Remove"created_at"and"updated_at"fromrender(2个答案)关闭5年前。我是Ruby的新手,所以这个问题对你来说可能看起来很愚蠢,是的。但还是...我有一个模型组,当我运行这个classGroupsController...然后我收到这样的数组响应:[{"id":1020,"name":"НІ-16-1","has_subgroups":true,"created_at":"2017-09-29T10:14:08.000Z","updated_at":"2017-09-29T10:14:08.000Z"}.