Displaying 20 results from an estimated 7000 matches similar to: "Extending a model in a component..."
2012 Sep 28
0
Overriding class_attribute writers and order of super/extend C.M./included block eval in ActiveSupport::Concern
I have:
module MySpike
extend ActiveSupport::Concern
included do
class_attribute :foobar, instance_writer: true
end
end
But, I want to be able to override the class attribute writer and/or
instance writer method to do something when the attribute is set via
self.foobar = true before or after calling super to set the attribute.
Unfortunately, I can''t find a clean way
2006 Jun 07
1
validates_presence_of in a mixed-in module?
Anyone got any idea of how to use built-in validation methods in a
mixed-in module.
What I''ve got at the moment is each class that needs ranking methods
includes [the module] Ranking. Then the module Ranking has a bunch of
instance methods and a submodule ClassMethods. The ClassMethods in this
are mixed in to the class with self.included. So far so good.
But I want the module to
2006 Mar 13
1
adding custom cache field
Hello,
I needed to add custom cache field for one of my application. I thought I
will share the code showing how to do this.
This code below creates and maintain a custom cache field, for keeping track
of totals. Say, you have accounts, and for each account there are transactions
(either deposit/withdrawal), and one will like to keep track of the total
balance for an account.
So, let there be a
2006 Jan 06
0
bug rails activerecord association join
hi,
I found a bug in ActiveRecord association SQL INNER JOIN codes. in
has_many, has_one, habtm and belongs_to queries the foreign key is
determined from the table name of reflection and self. but that''s
worng because if you use a global prefix or suffix for your tables the
foreign keys will be in format of PREFIX_CLASSNAME_SUFFIX_id which is
wrong, because it breaks the advantage of
2013 Jun 08
1
ActiveSupport::Concern support Module#prepend?
I''ve monkey patched this behavior into a gem and I was wondering if core
would be interested in a PR to add Module#prepend support to
ActiveSupport#Concern. I''ll add tests of course.
The code is here:
https://github.com/dockyard/easy_auth/blob/master/lib/easy_auth/active_support/concern.rb
My monkey patch work for what I''m trying to do but I suspect a better
2005 Dec 26
0
Why isn''t this working???
This is a very straightforward problem..
-I included a mixin in lib/ (see below)
-In environment.rb, I included the require statement (require
''acts_as_tree_additions'')
-Defined a method in the model:
def category_list
format_as_list #method in acts_as_tree_additions
end
-Called that method in the view..
I know the method is in the correct use, because it prints out a
2012 Sep 20
2
append_features(mod)
append_features(mod)
The documentation says:
When this module is included in another, Ruby calls append_features in
this module, passing it the receiving module in mod. Ruby’s default
implementation is to add the constants, methods, and module variables
of this module to mod if this module has not already been added to mod
or one of its ancestors. See also Module#include.
What if this module is
2006 Jul 04
1
How to override ActiveRecord#base#destroy
Hello,
I have a database table with a primary key not being a simple id but
three columns. By overriding update() and create() I got Rails to work
with that table quit good. Except for the destroy() action. From the
resulting trace I can see that the old version of destroy() is called
from transaction.rb. I think this lines might be the reason that I''m
unable to override detroy():
2006 Apr 18
4
Mixin variables
I''ve created an access control module that I''m including in several
different controllers. Everything works fine, but I want to allow each
controller to override the default login page with something like this:
set_login_pages :secure => ''my_login''
In my module, I''ve set up the set_login_pages method like this:
def self.included(base)
2006 May 17
3
Help mixin in class methods
Starting to feel more confident and code is DRYing up nicely, but I''ve
hit a brick wall here and hoping someone can help me.
I''ve got a module, TrustRanking, which extends a number of model''s
instance methods, and I want to extend their class methods too, but I
can seem to work out how to do it.
Simply including the module from the class works a treat for the
2005 Dec 02
43
ANN: acts_as_ferret
Hi all
This week I have worked with Rails and Ferret to test Ferrets (and Lucenes)
capabilities. I decided to make a mixin for ActiveRecord as it seemed the
simplest possible solution and I ended up making this into a plugin.
For more info on Ferret see:
http://ferret.davebalmain.com/trac/
The plugin is functional but could easily be refined. Anyway I want to share it
with you. Regard it as a
2005 Dec 02
43
ANN: acts_as_ferret
Hi all
This week I have worked with Rails and Ferret to test Ferrets (and Lucenes)
capabilities. I decided to make a mixin for ActiveRecord as it seemed the
simplest possible solution and I ended up making this into a plugin.
For more info on Ferret see:
http://ferret.davebalmain.com/trac/
The plugin is functional but could easily be refined. Anyway I want to share it
with you. Regard it as a
2009 Jan 03
0
understanding rails internal architecture
i am currently digging into the rails 2.2.2 source to get a deeper
understanding of some features (in particular model-validation) and a
better overall insight. most of rails features are encapsulated in a
separate module - as far as can see - and wired together through
mixins. this makes sense and following the logic in the single modules
is easy. but i am getting stuck while puzzling to see it
2006 May 31
1
Help enhancing acts_as_nested_set
I''m trying to enhance acts_as_nested_set. Well actually I already have,
but I''ve done a hack up job of it. I would like to contribute these
enhancements back, but I need a little help.
I''m a complete newbie to this stuff. The only thing I new before coming
into this project was vanilla HTML. So over the course of two weeks I''ve
picked up Ruby, Rails, MySQL,
2011 Feb 09
0
Weird error after upgrading to rails 3.0.4
Hey folks,
have you seen this ever?
[user@i ~/rails_project]$ rake rails:update --trace
(in /usr/home/rails_project)
rake aborted!
uninitialized constant ActiveModel::Validations::HelperMethods
/usr/local/lib/ruby/gems/1.8/gems/activemodel-3.0.4/lib/active_model/
validations.rb:50
/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.4/lib/
active_support/concern.rb:52:in `class_eval''
2009 Sep 11
0
Need help with extending a plugin
hey folks
I''ve installed the plugin acts_as_taggable_on_steroids (henceforth
aatos), and i already have some tagging functionality set up, using the
same approach (ie a Tag and a Tagging class with associated tables) as
aatos.
So, i want my existing Tag and Taggings methods, plus some other methods
i have in a module which i include with the taggable classes (ie the
ones that would call
2007 Jun 16
1
extending activerecord base with after_initialize
hi,
i am having problems getting after_initialize for activerecord
subclasses. basically, i am trying to use the guid plugin by andy
singleton. i am having problems extending the class to the plugins i
installed, so i figured i will just apply this to all the models in my
project. i trled to add the following to my lib/ folder. my goal is
to extended the activerecord class so that it uses
2007 Feb 02
0
Problem with ActiveForm
Hi all,
i''m using ActiveForm for some validations without a database. the
problem is, when i start my application, I get this error:
undefined method `save!'' for class `ActiveForm''
but if i refresh my browser, the application starts normally. im
guessing it''s because the ActiveForm class uses some things from active
record that haven''t been
2008 Jun 24
2
wrong number of arguments (1 for 0) when using respond_to?
Trying to get an otherwise working app (in Rails 2.0.2) up to speed
with Rails 2.1.0 and Ruby 1.8.7, I have some broken code I can''t seem
to fix:
module Pathmaker
def self.append_features( base )
base.before_save do |model|
model.path = model.name.downcase.
gsub( /\ and\ /, ''-'' ).
gsub( /\ on\ /, ''-'' ).
2007 Sep 18
2
Making attachment_fu polymorphic
I am working on a small model mixin called attachment_kung to make
attachment_fu polymorphic, so you no longer need a different table and
Model class for every associated attachment (Productimage, Ad_doc,
etc). All you really need is one model and table to handel all your
attachments - in some cases, anyway. I have the code working, but have
run into one small hitch that I can''t seem to