ChongQing Xiao
2004-Dec-06 18:25 UTC
question about post changes for a list of objects once
Hi, In the web browser, I have a grid to show a list of object (say a list of post or appt), the user can edit individual row in the client without post data back to server (using javascript), After the change, the user will click a submit key to post changes back to server and file the change once. Does rails have some standard way to handle this? Also for the following code (I copied from the example in active record) logger.info "\nUsing has_and_belongs_to_many association" david = Person.find(1) david.add_companies(thirty_seven_signals, next_angle) Is anyway to add the companies using company ID instead of using the company object so I don''t need to call company.FindOne("123") since I don''t need other information for the company? -- Something like David.add_companiesByID("123") Thanks chong
John Wilger
2004-Dec-06 18:52 UTC
Re: question about post changes for a list of objects once
It''s not necessarily a _Rails_ standard way to handle this, but it''s a simple enough solution---for each field, set up the inputs as array-style inputs and include the record''s id: <input type="text" name="myobjects[<%=obj.id%>][some_field]" /> Then, in the receiving controller, @params[''myobjects''] should be a collection of the input values keyed on each id, i.e.: @params[''myobjects''][1][''some_field''] @params[''myobjects''][24][''some_other_field''] etc. At least, this is the way, I''d expect @params to behave---anybody know differently? On Mon, 6 Dec 2004 12:25:25 -0600, ChongQing Xiao <cqxiao-VSMm719ZX/VmbZtjAW+qKA@public.gmane.org> wrote:> Hi, > > In the web browser, I have a grid to show a list of object (say a list > of post or appt), the user can edit individual row in the client without > post data back to server (using javascript), > After the change, the user will click a submit key to post changes back > to server and file the change once. > > Does rails have some standard way to handle this? > > Also for the following code (I copied from the example in active record) > logger.info "\nUsing has_and_belongs_to_many association" > david = Person.find(1) > david.add_companies(thirty_seven_signals, next_angle) > > Is anyway to add the companies using company ID instead of using the > company object so I don''t need to call company.FindOne("123") since I > don''t need other information for the company? > -- Something like David.add_companiesByID("123") > > Thanks > chong > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
ChongQing Xiao
2004-Dec-06 20:09 UTC
RE: question about post changes for a list of objects once
I see. So in the controller, I just manually get the ID and update each ID with the data in the fields. Thanks chong -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Wilger Sent: Monday, December 06, 2004 12:53 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] question about post changes for a list of objects once It''s not necessarily a _Rails_ standard way to handle this, but it''s a simple enough solution---for each field, set up the inputs as array-style inputs and include the record''s id: <input type="text" name="myobjects[<%=obj.id%>][some_field]" /> Then, in the receiving controller, @params[''myobjects''] should be a collection of the input values keyed on each id, i.e.: @params[''myobjects''][1][''some_field''] @params[''myobjects''][24][''some_other_field''] etc. At least, this is the way, I''d expect @params to behave---anybody know differently? On Mon, 6 Dec 2004 12:25:25 -0600, ChongQing Xiao <cqxiao-VSMm719ZX/VmbZtjAW+qKA@public.gmane.org> wrote:> Hi, > > In the web browser, I have a grid to show a list of object (say a list > of post or appt), the user can edit individual row in the clientwithout> post data back to server (using javascript), > After the change, the user will click a submit key to post changesback> to server and file the change once. > > Does rails have some standard way to handle this? > > Also for the following code (I copied from the example in activerecord)> logger.info "\nUsing has_and_belongs_to_many association" > david = Person.find(1) > david.add_companies(thirty_seven_signals, next_angle) > > Is anyway to add the companies using company ID instead of using the > company object so I don''t need to call company.FindOne("123") since I > don''t need other information for the company? > -- Something like David.add_companiesByID("123") > > Thanks > chong > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Dave Steinberg
2004-Dec-07 13:35 UTC
Re: question about post changes for a list of objects once
> Does rails have some standard way to handle this?<snip>> Is anyway to add the companies using company ID instead of using the > company object so I don''t need to call company.FindOne("123") since I > don''t need other information for the company? > -- Something like David.add_companiesByID("123")Right now I am pretty sure the answer is "no" at least without some manual fudgery mentioned by another poster. I had this proposal written up but life sucked me away from rails for a few weeks: http://actionpack.rubyonrails.org/show/FormBuildingByCollections Any feedback would be appreciated. :) Regards, -- Dave Steinberg http://www.geekisp.com/