简体   繁体   English

从gem上扩展ruby on rails activerecord

[英]extend ruby on rails activerecord from gem

I have an idea to write a gem but I don't have enough experience in extending ruby on rails. 我有一个想法写一个宝石,但我没有足够的经验在轨道上扩展ruby。

So here is what I want 所以这就是我想要的

For example here is a model file 例如,这是一个模型文件

class Modelname < ActiveRecord::Base
    methodname :columnname
end

So what "methodname" does is that it activates hook before db create/update and modifies "columnname" text 那么“methodname”的作用是它在db create / update之前激活hook并修改“columnname”文本

How is this different to 这有什么不同

Object.update_attribute( :columnname, "value" )

Or a before_filter that calls a method with the above behaviour? 或者调用具有上述行为的方法的before_filter?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM