"? I am using Ruby on Rails 3 and I am trying to use some kind of custom ...">

How to write my own method for ActiveRecord using "act_as_ <something>"?

I am using Ruby on Rails 3 and I am trying to use some kind of custom method for ActiveRecord so that I can do

Account.<my_method_name>

to add, for example, some data to the Account object (but without changing the account data itself).

I heard about the expression acts_as_<something>, and it is used, if I'm not mistaken, when creating plugins, but I did not understand if I needed it. After adding acts_as_<something>, perhaps I need to write somewhere a method similar to the following to “act” on the current ActiveRecord, which is called <my_method_name>:

def self.<my_method_name>
  ...
end

Can someone explain to me how to use this? And, if possible, can you give me a real example of its use?


BTW: lib RAILS_ROOT/app/lib?

+3
1

, = > http://thoughtsincomputation.com/posts/coding-an-acts_as-gem-for-rails-3

https://github.com/mbleigh/acts-as-taggable-on

Act_as * - . , ActsAs * . act_as *, ,

gem actions_as_taggable_on , .

act_as_taggable_on: ,:

, rails3 gem: actions_as_something

+3

All Articles