Displaying 20 results from an estimated 1000 matches similar to: "subclassing vs mixins, which one should be used?"
2008 Dec 08
3
Database calls in my views?
I am working on re-factoring my admittedly ambitious employee
management Rails app that I created for work. The good news is, my
first major version went over like a dream(With no small amount of
thanks due to the community and the support)! All of the functionality
the bosses dreamed of! The bad news? It''s REALLY SLOW. So I rolled up
my sleeves and have been working on some re-writes
2007 Nov 01
8
Specifying mixins
Hi folks,
Can anyone share some accumulated wisdom about the best way to spec
mixins in general, and (Jamis Buck-style) ActiveRecord "concerns" in
particular?
The standard situation here is that there''s a bunch of functionality,
related by concept if not by implementation, that one wants to inherit
in many different classes (e.g. ActiveRecord models) without having to
2010 Jan 26
6
Subclassing ActiveRecord::Base
First of all, sorry for the crossposting, but I put this into the Ruby
Forum first of all, but was pointed to this as a more appropriate
location.
I''m using ActiveRecord and ActiveSupport in a non-rails environment
to connect to multiple databases, and I''ve found the following (single
database) to cause me an error. Note that params is my database settings
and omitted for
2006 Jan 14
11
nuby: do models have to inherit directly from ActiveRecord?
Hello,
I have a few models -- book, cd, dvd -- for which I''d like to have an
abstract base superclass to hold some common stuff. That abstract class, I
was thinking, would inherit from ActiveRecord.
Didn''t work, though, and looking around, I found this:
<http://wiki.rubyonrails.com/rails/pages/HowtoMakeAbstractModel>
2006 May 08
4
Tables names with model classes in seperate modules
I have a module that deals with content pages and categories in my
application so create following tables:
content_pages
content_categories
Obviously I need a Page and Category module to map to these tables, but
in order to avoid conflicts with other Category classes, i declare my
model classes like this:
Content::Page
Content::Category
Now, that''s all fine - except that my models
2010 Nov 05
4
Inheritance alternative
I have to objects with common functionalities and a lot of difference.
So I want that each have his own table but inherit the common
functionalities from a parent class. How can I do this in Rails ?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2006 Feb 19
1
NOOB: ratings/voting mixin or code example?
so as to not reinvent the wheel, are there any exisiting examples or
mixins for a star rating system?
basically what i''m looking to do is show pictures of local models which
will be voted on by users, and the model with the most votes will get
her photo in a calendar.
anyone able to point me in the right direction... tutorials, code,
whatever would be greatly appreciated!
-A
--
2006 Nov 14
11
RESTful mixin, mixin repo?
Hi,
I just put together a little mixin to provide pseudo-RESTful services
in camping apps. Basically, it looks for a hidden _verb field in form
posts, and sets the @method to the supplied value (e.g. put or delete
- which browsers don''t support). This lets you define put and delete
methods in your controllers. Groovy.
Code:
http://pastie.caboo.se/22613
Is there any permanent repo of
2006 Mar 28
12
cached-model broken with Rails 1.1
It looks like cached-model is broken again under rails 1.1. Can anyone
confirm? Note that the exception below indicates it''s trying to treat
CachedModel as the class name of the model, rather than using the proper
class name (which is Entry in this case, and the table called entries).
This is a model using Single Table Inheritance and acts_as_tree, and
worked just fine under 1.0 and
2007 Oct 12
6
abstract_class... what exactly does it do
Hi,
Does anyone know much about abstract_class? Does it actually prevent
instances of the class from being created? Does it disable certain
methods? I already know what it''s for, but I want to know what setting
self.abstract_class=true actually does.
The reason I ask is that I want to use it for a slightly unorthodox
purpose. I want a class who''s only attributes are its
2009 Feb 02
2
ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
i keep getting this AssociationTypeMismatch error. i think this could
be a bug related to ruby/rails when using mixins. heres a short
version of my code:
# user.rb
require ''friend_invitation''
require ''friendship''
class User < ActiveRecord::Base
include FriendInvitationUser, FriendshipUser
...
end
# friendship.rb
...
module FriendshipUser
def
2006 Mar 05
8
Model Inheritance, Mixins and Database design
I''m trying to understand how best to use inheritance and wonder if
Rail''s Single Table Inheritance model too restricting.
I have a model Companies who provide 1+ Services (HABTM relationship).
I assume the best way to represent this is with a series of child models
representing each type of service : ServiceType < Company.
I want to return lists of companys for each
2007 Feb 08
0
derive.js - Ruby-esque derivation/mixins for Prototype
All,
I whipped up a small extension for Prototype to solve some modeling
issues I was having on a large JS project.
I know there have been serveral alternative "write JS in Ruby" type
efforts, including ruby.js, rb2js, and prototype.js itself, but I was
hoping to keep it as light as possible while gaining the most powerful
aspects of derivation/mixins/callbacks. Much like the prototype
2006 May 11
1
Mixins
If I want to write a function which will be available to views, I write
a helper function in one of the places set aside or that very task by Rails.
If I want to write a little suite of functions to be mixed in by a
number of model classes (but not all), where do I put them? Plug-ins
look like AN answer, but they also seem a little heavyweight for simple,
project-specific tasks.
2005 Nov 06
1
mixins not reloaded as expected?!
Hi guys,
in development mode a module mixed into a helper class seems not to be
reloaded
inside app/helpers:
class TestHelper
include EvenMoreHelp
#foo
end
module EvenMoreHelp
# bar
end
the contents of #foo get refreshed, but not #bar...
is there a way to fix that behaviour.
I intend a full reload in development mode for obvious reasons.
Regards
Peter
2007 May 01
2
Using mixins versus delegation
I''ve been working on a plugin called Http Test where I add HTML
validation and link checking to controller and integration tests
through an after filter in ApplicationController. I used to mix in a
bunch of methods that I needed into the ApplicationController class,
but to me this had a bad smell, so I broke much of the code out into
separate classes that I delegate to.
2006 Apr 11
1
Mixins?
As is often the case when I tackle a new platform/language, I get the big
picture very quickly (because frameworks are frameworks are frameworks) but
its the nitty-gritty of the language that bogs me down...
So I have some similar methods on a few of my model classes that I wanted to
push into a helper. Now I reckoned that the Ruby way was to create a module
and mix it in with include. However, I
2007 Oct 24
6
how to subclass active record to call a method on all save and destroy actions
I''m looking for a way to subclass active record (I''ll refer to the
subclass I want to create as NewActiveRecord) so that I can call
different methods on a save or destroy action on all models which sub
class NewActiveRecord
I dont want to use before_save or any of the other regular call back
methods as I want to be able to use these call backs in the models
which subclass
2008 Jul 10
6
Uppercase all row columns
Hi.
I have to convert the contents of all columns to uppercase before
creating a row. Is there an easy way to accomplish this so I don''t
have to go one column at a time and upcase! it?
Thanks.
Pepe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group,
2006 Jul 26
4
Execute code when an inheritance happens, or disabling STI
I am trying to inherit from a ActiveRecord class defined in a plugin.
The problem is that ActiveRecord thinks I am doing an STI and is looking
up a table that doesn''t exist.
Currently, I have a method in the parent class that looks like this:
def self.fix_table_name
class_eval do
set_table_name(Inflector.tableize(self.to_s))
end
end
The problem is that this method