Hi,
I am using ''set_table_name'' in all my models, I want one
abstract class
which extends from ActiveRecord::Base and all my model should extends
from this abstract class. i will write setter method in abstrct class
which will set table name also i am able to override that method in my
model. my question is this is possible in rails? how to implement this
in rails?
e.g:-
class Abstract < ActiveRecord::Base
def set_table_name(table_name)
return "prefix" + table_name
end
end
class Photo < Abstract
? From here hoe to make a call for set_table_name
end
--
Posted via http://www.ruby-forum.com/.
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 25, 6:07 am, Sunny Bogawat <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I am using ''set_table_name'' in all my models, I want one abstract class > which extends from ActiveRecord::Base and all my model should extends > from this abstract class. i will write setter method in abstrct class > which will set table name also i am able to override that method in my > model. my question is this is possible in rails? how to implement this > in rails?If all you want to do is add a prefix, I''d just set Abstract.table_name_prefix Fred> > e.g:- > > class Abstract < ActiveRecord::Base > def set_table_name(table_name) > return "prefix" + table_name > end > end > > class Photo < Abstract > ? From here hoe to make a call for set_table_name > end > -- > Posted viahttp://www.ruby-forum.com/.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
try something like this. U need not call set_table_name from child class as
long as model name
matches with database table using prefix string.
class Abstract < ActiveRecord::Base
set_table_name "some_prefix_#{self.to_s.tableize}"
end
If you want to override then
class Photo < Abstract
set_table_name "some_different_table_from regular pattern"
end
On Wed, Aug 25, 2010 at 10:37 AM, Sunny Bogawat
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:
> Hi,
>
> I am using ''set_table_name'' in all my models, I want one
abstract class
> which extends from ActiveRecord::Base and all my model should extends
> from this abstract class. i will write setter method in abstrct class
> which will set table name also i am able to override that method in my
> model. my question is this is possible in rails? how to implement this
> in rails?
>
> e.g:-
>
> class Abstract < ActiveRecord::Base
> def set_table_name(table_name)
> return "prefix" + table_name
> end
> end
>
> class Photo < Abstract
> ? From here hoe to make a call for set_table_name
> end
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
Sandip
---
blog www.funonrails.com
twitter @sandipransing
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.