jjzjj

my_concern_magic

全部标签

ruby-on-rails - my_object.save(false) 并没有真正跳过我的 Active Record 验证

所以我一直在努力解决我一直遇到的这个错误,我终于找到了导致它的原因。我一直觉得,当我调用@my_model.save(false)我会跳过我的ActiveRecord验证。事实证明这是部分正确的。我的对象正在保存到数据库中DESPITE我的ActiveRecord验证。我的问题存在是因为我的一个验证在验证过程中修改了一个子模型(这是一个24小时位置的调度应用程序,因此当午餐被保存时,我对照他们保存的那天和第二天检查它们以及确保用户不是指“凌晨2点”表示要上夜类。我的问题是:有没有办法真正跳过我的验证并直接移动到数据库?这是正常的ActiveRecord行为还是我应该更深入地研究我的验证

ruby - 使用扩展 ActiveSupport::Concern

我正在研究CodeSchool的RubyBits,我做了一个我只是不理解的练习:“确保AtariLibrary类只包含LibraryUtils模块,并让ActiveSupport::Concern负责加载它的依赖项。然后,重构LibraryUtils上的self.included方法以使用包含的方法。”moduleLibraryLoaderextendActiveSupport::ConcernmoduleClassMethodsdefload_game_listendendendmoduleLibraryUtilsdefself.included(base)base.load_gam

ruby-on-rails - 在 ActiveSupport::Concern 中访问包含类的 protected 常量

在ActiveSupport::Concern上下文中访问包含类的protected常量的最简单方法是什么?示例类:modulePrintableextendActiveSupport::Concernprivatedefprint_constantputsMY_CONSTANTendendclassPrinterincludePrintabledefprintprint_constantendprivateMY_CONSTANT='Hello'.freezeend此解决方案产生错误:NameError:uninitializedconstantPrintable::MY_CONSTA

ruby-on-rails - rails : I installed ActiveAdmin and my devise link stopped working

我已经安装了设备。我有一个链接:当我安装ActiveAdmin(对于现有型号User)时,此链接停止工作:undefinedlocalvariableormethod`new_user_registration_path'我对routes.rb使用了gitdiff在这里(添加的行是黑色的):ActiveAdmin.routes(self)devise_for:users,ActiveAdmin::Devise.config还有:delete%>现在导致/admin/logout我该如何解决这个问题?rake路:admin_dashboard/admin(.:format){:actio

ruby-on-rails - rake 数据库 :migrate not working on my postgres db

好的,所以我有一个Rails应用程序,我试图在postgres数据库上运行迁移,我通常使用mysql,一切都很好,但是当我运行命令时,我得到了这个rakedb:migrate(in/Users/tamer/Sites/my_app)/Users/tamer/.rvm/gems/ruby-1.9.2-p290@my_app/gems/activerecord-3.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:487:[BUG]Segmentationfaultruby1.9.2p290(2011-07-09

ruby-on-rails - 如何在使用 Ruby on Rails ActiveSupport::Concern 功能时包含模块 "nest"?

我正在使用Ruby1.9.2和RubyonRailsv3.2.2gem。我想“嵌套”模块的包含,因为我正在使用RoRActiveSupport::Concern功能,但我怀疑我应该在哪里声明include方法。也就是说,我有以下内容:moduleMyModuleAextendActiveSupport::Concern#includeMyModuleBincludeddo#includeMyModuleBendend应该我在MyModuleA的“正文”/“上下文”/“范围”中声明includeMyModuleB或者我应该声明包含的do...endblock?有什么区别,我应该从中得到什

ruby-on-rails - 在 ActiveSupport::Concern 中重载方法

我这样写怎么会有顾虑呢:moduleConcernsmoduleMyConcernextendActiveSupport::Concern...defmy_concern_magic(arg0,arg1)#excitingstuffhereendendend包含在重载my_concern_magic的模型中?例如。classUserincludeConcerns::MyConcern...defmy_concern_magic(arg0)arg1=[1,2,3]my_concern_magic(arg0,arg1)endend 最佳答案

ruby-on-rails - rails : Can't access a module in my lib directory

我想创建一个通用的字符串操作类,可以在我的Rails应用程序中跨模型、View和Controller使用。现在,我正试图将一个模块放入我的lib目录中,我只是试图访问Rails控制台中的函数来测试它。我已经尝试了很多来自类似问题的技术,但我无法让它发挥作用。在我的lib/filenames.rb文件中:moduleFilenamesdefsanitize_filename(filename)#Replaceanynon-letterornon-numbercharacterwithaspacefilename.gsub!(/[^A-Za-z0-9]+/,'')#removespaces

ruby-on-rails - 覆盖由同一模块中的类方法定义的 ActiveSupport::Concern 模块中的方法

我有一个ActiveSupport::Concern模块,大致如下所示:moduleMyModelmoduleAcceptanceextendActiveSupport::Concernincludeddoenumstatus:[:declined,:accepted]enddefdeclined!self.status=:declined#someextralogicself.save!enddefaccepted!self.status=:accepted#someextralogicself.save!endendend这只会被包含到ActiveRecord类中,因此使用enum

ruby-on-rails - rails : dynamically define class method based on parent class name within module/concern

我想根据包含此Mixin的类名在Mixin中动态生成一个类方法。这是我当前的代码:moduleMyModuleextendActiveSupport::Concern#defsome_methods#...#endmoduleClassMethods#HereiswhereI'mstuck...define_method"#{self.name.downcase}_status"do#dosomething...endendendclassMyClass但这给了我以下方法名称:MyClass.mymodule::classmethods_status在方法定义中获取基类名称是可行的(s