idmkid
2007-Apr-10 22:49 UTC
Populating a column automatically based on the sum of other columns in the same row
I am new to Ruby on Rails and love what I see. I am also new to MySQL. I am using a generic table with the ajax_scaffold. The table and application are working great. However, I want to populate one column for a new row based on the sum of other columns inputed by the user when a new row is created. The row represents a new user. Some of the columns for the user represent test scores. One column is for a total score. How do I add up the columns with scores and populate the total score column dynamically? Thanks, Idmkid --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tyler Prete
2007-Apr-10 22:55 UTC
Re: Populating a column automatically based on the sum of other columns in the same row
You might want to look into Active Scaffold (http://www.activescaffold.com). It''s the successor to ajax scaffold, and it makes things like column totals really easy to do. --Tyler On 4/10/07, idmkid <fpatterson55-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I am new to Ruby on Rails and love what I see. I am also new to MySQL. > > I am using a generic table with the ajax_scaffold. The table and > application are working great. However, I want to populate one column > for a new row based on the sum of other columns inputed by the user > when a new row is created. > > The row represents a new user. Some of the columns for the user > represent test scores. One column is for a total score. How do I add > up the columns with scores and populate the total score column > dynamically? > > Thanks, > Idmkid > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten
2007-Apr-11 08:19 UTC
Re: Populating a column automatically based on the sum of other columns in the same row
Simply use a AR Callback: class User < Active_Record::Base before_create :sum_scores private def sum_scores self.total_score = self.score1 + self.score2 end end On 11 Apr., 00:55, "Tyler Prete" <psyo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You might want to look into Active Scaffold (http://www.activescaffold.com). > It''s the successor to ajax scaffold, and it makes things like column totals > really easy to do. > > --Tyler > > On 4/10/07, idmkid <fpatterso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am new to Ruby on Rails and love what I see. I am also new to MySQL. > > > I am using a generic table with the ajax_scaffold. The table and > > application are working great. However, I want to populate one column > > for a new row based on the sum of other columns inputed by the user > > when a new row is created. > > > The row represents a new user. Some of the columns for the user > > represent test scores. One column is for a total score. How do I add > > up the columns with scores and populate the total score column > > dynamically? > > > Thanks, > > Idmkid- Zitierten Text ausblenden - > > - Zitierten Text anzeigen ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---