Okay I have a "list" view that contains a package inventory stored in a table called addpackages. Attributes include fname, lname, packagetype, email, phone, etc. Here''s what I''ve done already: 1. When you click the last name of a person in the list view simulating they are picking the package up, you go to my custom edit view. <td><%= link_to addpackage.lname, :action => "edit", :id => addpackage.id %></td> 2. Here is my custom edit view: <form action="../update/<%= @addpackage.id %>" method="POST""> <input id="addpackage_id" name="addpackage[id]" size="30" type="hidden" value="<%= @addpackage.id %>" /> <p><b>User must enter initials to claim package:</b><br> <input id="addpackage_signature" name="addpackage[signature]" size="5" type="text" value="<%= @addpackage_signature %>" /> </p> <input type="submit" value="Sign for package" /> </form> 3. This all works fine for getting the signature in the addpackages table. What I would like to do at this point is copy a few attributes(lname, fname, signature, phone) to a table called receipts? I''ve already created a relationship between addpackages and receipts, I just need help with coding behind this operation. I figure I would perform this operation in the addpackage controller under "def edit" but I really need a kick start to coding this or someone to tell me this is the correct way to do it. Help will be greatly greatly appreciated!!! -Tony -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Wai Tsang
2007-Apr-25 15:38 UTC
Re: Moving multiple attributes to a new table - please help!
Tony M. wrote:> What I would like to do at this point is copy a few > attributes(lname, fname, signature, phone) to a table called receipts? > I''ve already created a relationship between addpackages and receipts, I > just need help with coding behind this operation. I figure I would > perform this operation in the addpackage controller under "def edit" but > I really need a kick start to coding this or someone to tell me this is > the correct way to do it.It would really help if you could give us the relationships between the models. From my understanding, you are trying to copy the fields from one table to another right? In that case, you can look up the package record in the receipt model and copy the attributes to the current records. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Tony M.
2007-Apr-25 18:03 UTC
Re: Moving multiple attributes to a new table - please help!
Wai Tsang wrote:> Tony M. wrote: >> What I would like to do at this point is copy a few >> attributes(lname, fname, signature, phone) to a table called receipts? >> I''ve already created a relationship between addpackages and receipts, I >> just need help with coding behind this operation. I figure I would >> perform this operation in the addpackage controller under "def edit" but >> I really need a kick start to coding this or someone to tell me this is >> the correct way to do it. > > It would really help if you could give us the relationships between the > models. From my understanding, you are trying to copy the fields from > one table to another right? In that case, you can look up the package > record in the receipt model and copy the attributes to the current > records.I think we are on the same page, but here''s a visual representation just in case. 1: The ID# is clicked when a user comes to the mailroom to get their package http://aycu34.webshots.com/image/15313/2002794410554314194_rs.jpg 2: The app will prompt for the users initials http://aycu24.webshots.com/image/15343/2002700669700389807_rs.jpg 3: Upon clicking the Sign for package, the initials/date are logged, and what I want to happen is to copy all all fields needed to fill this following Receipts table, and at the same time delete the selected record from Inventory, as the package has been picked up and it is no longer in the mailroom. http://aycu01.webshots.com/image/13400/2002736555382712550_rs.jpg Here are my relations at the moment: class Addpackage < ActiveRecord::Base belongs_to :category has_and_belongs_to_many :rosters has_many :receipts end class Receipt < ActiveRecord::Base has_and_belongs_to_many :addpackages end I''ve been trying to do this operation from both the addpackage controller and receipt controller but have failed. I''m still a newbie to rails so it might just be my syntax or incomplete knowledge. You said above I could perform all these operations from receipt.db model? I have never put anything but relations in those. Anyway I have exhausted myself trying to get this to work. I''ll keep hacking at it, but im not getting much of anywhere. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Tony M.
2007-Apr-25 20:06 UTC
Re: Moving multiple attributes to a new table - please help!
2 hours later I still can''t figure out how to make this work. Are my relations correct? If someone could throw me a couple lines of code or even point me in the right direction it would really make my day!! - -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Tony M.
2007-Apr-25 21:09 UTC
Re: Moving multiple attributes to a new table - please help!
Sorry to be such a bother but this is the only thing keeping me from completing my little project and im going bonkers lol. If anyone can throw me a bone now I will return the favor later. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
The very words ''copy attributes'' should send shivers down your spine as a Rails developer. It really sounds like what you''ve got is a third object that is related to packages and receipts -- user/person/ addressee or something of that sort. I''d think something like: class User < ActiveRecord::Base has_many :packages has_many :receipts ... end (the class above carries the data you want to copy -- name fields, etc) class AddPackage < ActiveRecord::Base belongs_to :user .. end class Receipt < ActiveRecord::Base belongs_to :user ... end Your User class could have a method that "transfers" the item from "Inventory" (I don''t see any class relationship for that) to Receipts: def signed_for(add_package) self.receipts.create(:add_package_id => add_package.id, :picked_up_at => Time.now) # some code to remove add_package from inventory end Note: It''s MUCH better to put this type of business logic in the model and not the controller. HTH, Andy On Apr 25, 5:09 pm, "Tony M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Sorry to be such a bother but this is the only thing keeping me from > completing my little project and im going bonkers lol. If anyone can > throw me a bone now I will return the favor later. > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---