I am sitting with the Agile book on my desk and scratching my head at the discussion on aggregation - perhaps that isn''t what I need. I have a db called clients. fields include - first_name middle_initial last_name I want to combine them all into one name element in a list view. I can add/edit the fields separately but in the list view, I only want the one combo field. Is there a documentation page that describes this? I have browsed the rubyonrails.org wiki and haven''t stumbled into an appropriate page. Pointers to references would be greatly appreciated. Thanks Craig
Craig: There''s a neat way you can do that in the model. I saw it once but was busy and didn''t commit it to memory. That was the semi-bad news. The good news is that you can do that in MySQL really easily (I hope you are using MySQL select concat(first_name," ",middle_initial," ",last_name) as name, other fields go here from table where etc. bruce On 24-Jan-06, at 8:46 PM, Craig White wrote:> I am sitting with the Agile book on my desk and scratching my head at > the discussion on aggregation - perhaps that isn''t what I need. > > I have a db called clients. > fields include - first_name middle_initial last_name > > I want to combine them all into one name element in a list view. I can > add/edit the fields separately but in the list view, I only want > the one > combo field. > > Is there a documentation page that describes this? I have browsed the > rubyonrails.org wiki and haven''t stumbled into an appropriate page. > > Pointers to references would be greatly appreciated. > > Thanks > > Craig > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Yeah - I''m looking for the model methodology and I''m using postgres at the moment here and I''m thinking that I want to keep it as abstract as possible. thanks Craig On Tue, 2006-01-24 at 22:08 -0700, Bruce Balmer wrote:> Craig: > > There''s a neat way you can do that in the model. I saw it once but > was busy and didn''t commit it to memory. That was the semi-bad news. > The good news is that you can do that in MySQL really easily (I hope > you are using MySQL > > select concat(first_name," ",middle_initial," ",last_name) as name, > other fields go here from table where etc. > > bruce > > > On 24-Jan-06, at 8:46 PM, Craig White wrote: > > > I am sitting with the Agile book on my desk and scratching my head at > > the discussion on aggregation - perhaps that isn''t what I need. > > > > I have a db called clients. > > fields include - first_name middle_initial last_name > > > > I want to combine them all into one name element in a list view. I can > > add/edit the fields separately but in the list view, I only want > > the one > > combo field. > > > > Is there a documentation page that describes this? I have browsed the > > rubyonrails.org wiki and haven''t stumbled into an appropriate page. > > > > Pointers to references would be greatly appreciated. > > > > Thanks > > > > Craig > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
This breaks the normal rules of db, but I just create a name field and add a
before_save event to concatenate the individual names into the full name.
This makes everything simpler for no real cost other than some rules. Who
lives by the rules anyways? :)
Before_save :fix_name
def fix_name
record.full_name = "#{record.first_name} #{record.last_name}"
end
Not pretty but makes a lot of things lots easier, like in my case,
auto_complete_fields.
Bob
> -----Original Message-----
> From: rails-bounces@lists.rubyonrails.org [mailto:rails-
> bounces@lists.rubyonrails.org] On Behalf Of Craig White
> Sent: Tuesday, January 24, 2006 9:20 PM
> To: rails@lists.rubyonrails.org
> Subject: Re: [Rails] join fields for list views
>
> Yeah - I''m looking for the model methodology and I''m
using postgres at
> the moment here and I''m thinking that I want to keep it as
abstract as
> possible.
>
> thanks
>
> Craig
>
> On Tue, 2006-01-24 at 22:08 -0700, Bruce Balmer wrote:
> > Craig:
> >
> > There''s a neat way you can do that in the model. I saw it
once but
> > was busy and didn''t commit it to memory. That was the
semi-bad news.
> > The good news is that you can do that in MySQL really easily (I hope
> > you are using MySQL
> >
> > select concat(first_name," ",middle_initial,"
",last_name) as name,
> > other fields go here from table where etc.
> >
> > bruce
> >
> >
> > On 24-Jan-06, at 8:46 PM, Craig White wrote:
> >
> > > I am sitting with the Agile book on my desk and scratching my
head at
> > > the discussion on aggregation - perhaps that isn''t what
I need.
> > >
> > > I have a db called clients.
> > > fields include - first_name middle_initial last_name
> > >
> > > I want to combine them all into one name element in a list view.
I can
> > > add/edit the fields separately but in the list view, I only want
> > > the one
> > > combo field.
> > >
> > > Is there a documentation page that describes this? I have browsed
the
> > > rubyonrails.org wiki and haven''t stumbled into an
appropriate page.
> > >
> > > Pointers to references would be greatly appreciated.
> > >
> > > Thanks
> > >
> > > Craig
> > >
> > > _______________________________________________
> > > Rails mailing list
> > > Rails@lists.rubyonrails.org
> > > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
The Agile book isn''t clear to me.
I have clients database...fields:
first_name
middle_initial
last_name
In client.rb I have
class Client < ActiveRecord::Base
has_one :case_manager
has_many :placements
composed_of :name,
:class_name => Name,
:mapping =>
[[ first_name, :first_name ],
[ middle_initial, :middle_initial ],
[ last_name, :last_name ]
]
end
and I have models/name.rb which has...
class Name
attr_reader :first_name, :middle_initial, last_name
def initialize(first_name, middle_initial, last_name)
@first_name = first_name
@middle_initial = middle_initial
@last_name = last_name
end
end
and when I try to view a page, I get an error...undefined local variable
or method ''first_name'' for Client:Class
I''m clearly missing something.
Craig
On Tue, 2006-01-24 at 21:27 -0800, Bob Silva wrote:> This breaks the normal rules of db, but I just create a name field and add
a
> before_save event to concatenate the individual names into the full name.
> This makes everything simpler for no real cost other than some rules. Who
> lives by the rules anyways? :)
>
> Before_save :fix_name
>
> def fix_name
> record.full_name = "#{record.first_name} #{record.last_name}"
> end
>
> Not pretty but makes a lot of things lots easier, like in my case,
> auto_complete_fields.
>
> Bob
>
Try client.name.first_name? On 1/24/06, Craig White <craigwhite@azapple.com> wrote:> > The Agile book isn''t clear to me. > > I have clients database...fields: > first_name > middle_initial > last_name > > In client.rb I have > > class Client < ActiveRecord::Base > has_one :case_manager > has_many :placements > > composed_of :name, > :class_name => Name, > :mapping => > [[ first_name, :first_name ], > [ middle_initial, :middle_initial ], > [ last_name, :last_name ] > ] > end > > and I have models/name.rb which has... > class Name > attr_reader :first_name, :middle_initial, last_name > > def initialize(first_name, middle_initial, last_name) > @first_name = first_name > @middle_initial = middle_initial > @last_name = last_name > end > end > > and when I try to view a page, I get an error...undefined local variable > or method ''first_name'' for Client:Class > > I''m clearly missing something. > > Craig > > On Tue, 2006-01-24 at 21:27 -0800, Bob Silva wrote: > > This breaks the normal rules of db, but I just create a name field and > add a > > before_save event to concatenate the individual names into the full > name. > > This makes everything simpler for no real cost other than some rules. > Who > > lives by the rules anyways? :) > > > > Before_save :fix_name > > > > def fix_name > > record.full_name = "#{record.first_name} #{record.last_name}" > > end > > > > Not pretty but makes a lot of things lots easier, like in my case, > > auto_complete_fields. > > > > Bob > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060125/ef1d3703/attachment-0001.html
On Wed, 2006-01-25 at 00:02 -0600, Steve Longdo wrote:> Try client.name.first_name?---- that just generates new errors. I''ve fixed one of my errors as listed below...and now I get a hashed value for the ''Name'' field... like #<Name:0xb7b4305c> it''s better than an error I guess but it isn''t what I expected. Craig> > On 1/24/06, Craig White <craigwhite@azapple.com> wrote: > The Agile book isn''t clear to me. > > I have clients database...fields: > first_name > middle_initial > last_name > > In client.rb I have > > class Client < ActiveRecord::Base > has_one :case_manager > has_many :placements > > composed_of :name, > :class_name => Name, > :mapping => > [[ :first_name, :first_name ], > [ :middle_initial, :middle_initial ], > [ :last_name, :last_name ] > ] > end > > and I have models/name.rb which has... > class Name > attr_reader :first_name, :middle_initial, last_name > > def initialize(first_name, middle_initial, last_name) > @first_name = first_name > @middle_initial = middle_initial > @last_name = last_name > end > end > > and when I try to view a page, I get an error...undefined > local variable > or method ''first_name'' for Client:Class > > I''m clearly missing something. > > Craig > > On Tue, 2006-01-24 at 21:27 -0800, Bob Silva wrote: > > This breaks the normal rules of db, but I just create a name > field and add a > > before_save event to concatenate the individual names into > the full name. > > This makes everything simpler for no real cost other than > some rules. Who > > lives by the rules anyways? :) > > > > Before_save :fix_name > > > > def fix_name > > record.full_name = "#{ record.first_name} > #{record.last_name}" > > end > > > > Not pretty but makes a lot of things lots easier, like in my > case, > > auto_complete_fields. > > > > Bob > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I had to put both declarations in the client.rb file. On Tue, 2006-01-24 at 23:23 -0700, Craig White wrote:> On Wed, 2006-01-25 at 00:02 -0600, Steve Longdo wrote: > > Try client.name.first_name? > ---- > that just generates new errors. > > I''ve fixed one of my errors as listed below...and now I get a hashed > value for the ''Name'' field... like #<Name:0xb7b4305c> > > it''s better than an error I guess but it isn''t what I expected. > > Craig > > > > > On 1/24/06, Craig White <craigwhite@azapple.com> wrote: > > The Agile book isn''t clear to me. > > > > I have clients database...fields: > > first_name > > middle_initial > > last_name > > > > In client.rb I have > > > > class Client < ActiveRecord::Base > > has_one :case_manager > > has_many :placements > > > > composed_of :name, > > :class_name => Name, > > :mapping => > > [[ :first_name, :first_name ], > > [ :middle_initial, :middle_initial ], > > [ :last_name, :last_name ] > > ] > > end > > > > and I have models/name.rb which has... > > class Name > > attr_reader :first_name, :middle_initial, last_name > > > > def initialize(first_name, middle_initial, last_name) > > @first_name = first_name > > @middle_initial = middle_initial > > @last_name = last_name > > end > > end > > > > and when I try to view a page, I get an error...undefined > > local variable > > or method ''first_name'' for Client:Class > > > > I''m clearly missing something. > > > > Craig > > > > On Tue, 2006-01-24 at 21:27 -0800, Bob Silva wrote: > > > This breaks the normal rules of db, but I just create a name > > field and add a > > > before_save event to concatenate the individual names into > > the full name. > > > This makes everything simpler for no real cost other than > > some rules. Who > > > lives by the rules anyways? :) > > > > > > Before_save :fix_name > > > > > > def fix_name > > > record.full_name = "#{ record.first_name} > > #{record.last_name}" > > > end > > > > > > Not pretty but makes a lot of things lots easier, like in my > > case, > > > auto_complete_fields. > > > > > > Bob > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails