Hi all, this is my first post here. I have several Rails books here that I''m working and I''m trying to "get the light bulb to turn on." I''m attempting a small application that processes account applications, and if approved, turns them into clients. I''ve got account_application and client models. I have the a_a side working reasonably well. I have a list of pending applications, I can review them individually, and approve or decline them. Upon approval what I want to do is conceptually simple, but I just can''t figure out where it "belongs." When I have an approved application I''d like to create a client based on that application. The client will get an an account number and such, and also retain a "has one" relationship with the application. Where do I make that happen? In the client model? The client controller? Also, can I create an account application with a "belongs to" before I have a client to which it can belong? I think my biggest hurdle is that I don''t yet grasp how the Rails "magic" works, and so I don''t know how to fit it in. Thanks for any guidance, -George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Hi all, > this is my first post here. I have several Rails books here that I''m > working and I''m trying to "get the light bulb to turn on." > > I''m attempting a small application that processes account > applications, and if approved, turns them into clients. I''ve got > account_application and client models. I have the a_a side working > reasonably well. I have a list of pending applications, I can review > them individually, and approve or decline them. > > Upon approval what I want to do is conceptually simple, but I just > can''t figure out where it "belongs." When I have an approved > application I''d like to create a client based on that application. > The client will get an an account number and such, and also retain a > "has one" relationship with the application. > > Where do I make that happen? In the client model? The client controller? > Also, can I create an account application with a "belongs to" before > I have a client to which it can belong? > > I think my biggest hurdle is that I don''t yet grasp how the Rails > "magic" works, and so I don''t know how to fit it in.You could have an application without a client by setting client_id to nil. Can''t think of a reason that wouldn''t work. But you could also create the client fully on submission and if the application is denied and it''s the only one that client has, remove them. Or have some other status field for the client or something such that you can create it when the application is submitted. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On May 1, 2007, at 4:15 PM, List Catcher wrote:> Upon approval what I want to do is conceptually simple, but I just > can''t figure out where it "belongs." When I have an approved > application I''d like to create a client based on that application. > The client will get an an account number and such, and also retain a > "has one" relationship with the application. > > Where do I make that happen? In the client model? The client > controller? > Also, can I create an account application with a "belongs to" before > I have a client to which it can belong? > > I think my biggest hurdle is that I don''t yet grasp how the Rails > "magic" works, and so I don''t know how to fit it in.You can definitely declare the relationship before the records exist. Just declare the relationships as you would if there were data. As to creating the account, you may want to look into ActiveRecord callbacks [1] and have something like class AccountApplication < ActiveRecord::Base after_save :process_new_account def process_new_account if self.status == ''approved'' and self.client.nil? # Create client here end end end James. 1: http://rails.rubyonrails.org/classes/ActiveRecord/Callbacks.html -- James Stewart http://jystewart.net/process/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On May 1, 2007, at 2:49 PM, James Stewart wrote:> As to creating the account, you may want to look into ActiveRecord > callbacks [1] and have something like > > class AccountApplication < ActiveRecord::Base > after_save :process_new_account > > def process_new_account > if self.status == ''approved'' and self.client.nil? > # Create client here > end > end > endHey! The light bulb just got a little less dim! :-) That feels right, and I''d never have thought of it. Thanks! -George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---