Ok, I know this has to be EXTREMELY simple, so please excuse the ignorance. However, I want the button_to method to execute some external javascript function I have predefined called "addRow()" when the user clicks the button. I see all these examples of button_to .... :confirm => "Are you sure?", but that is the ONLY example I see for button_to html_options. I attempted this button_to ....:onclick => "addRow()", but it appends this to the url ?onclick=addRow(). Anyone? Anyone? Show me just how dumb I am this afternoon. It won''t hurt my feelings in the least. Thanks in advance. ~d _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think you can use one of: <%= link_to_function "Add Row", "addRow()" %> <%= tag "input", { "type" => "button", "value" => "Add Row", "onclick" => "addRow()" } %> <%= button_to "Add Row", "javascript:addRow()" %> Best regards, torben -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Damon Hill Sent: 22. november 2005 20:38 To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] button_to execute javascript function Ok, I know this has to be EXTREMELY simple, so please excuse the ignorance. However, I want the button_to method to execute some external javascript function I have predefined called "addRow()" when the user clicks the button. I see all these examples of button_to .... :confirm => "Are you sure?", but that is the ONLY example I see for button_to html_options. I attempted this button_to ....:onclick => "addRow()", but it appends this to the url ?onclick=addRow(). Anyone? Anyone? Show me just how dumb I am this afternoon. It won''t hurt my feelings in the least. Thanks in advance. ~d _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 22.11.2005, at 21.37, Damon Hill wrote:> > > I attempted this button_to ....:onclick => "addRow()", but it > appends this to the url ?onclick=addRow().You have the onclick attribute in the url options hash. Try to divide it up to two hashes and you should be fine. //jarkko> > Anyone? Anyone? > > Show me just how dumb I am this afternoon. > It won''t hurt my feelings in the least. > > Thanks in advance. > ~d > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the replies Jarkko and Torben. I can now successfully insert rows into my table upon a button click. However, the next question I have is, can I insert rails code as TD elements into the table. For example, I need to insert the following two elements in the TR I am inserting: <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> <%= text_field_with_auto_complete :product, :product_name %></td> However, whenever I attemp to insert those, I get just the TEXT, not the functionality of the methods. I am using the following to insert the row into the table: new Insertion.Bottom(''po_products'', completeRow); Obviously, the po_products is my table id, and the complete Row is the entire string to insert into the HTML. Thoughts??? Thanks for all the help: ~damon On 11/22/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > > On 22.11.2005, at 21.37, Damon Hill wrote: > > > > > > I attempted this button_to ....:onclick => "addRow()", but it > > appends this to the url ?onclick=addRow(). > > You have the onclick attribute in the url options hash. Try to divide > it up to two hashes and you should be fine. > > //jarkko > > > > > Anyone? Anyone? > > > > Show me just how dumb I am this afternoon. > > It won''t hurt my feelings in the least. > > > > Thanks in advance. > > ~d > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
The text_field et al. commands just return their respective HTML. That''s not working because your completeRow is not processed again by ERb before hitting the browser. You may have luck with: completeRow << text_field(...) ... new InsertionBottom(''po_products'', completeRow) if the code in question is in your view. Otherwise you may have to include ActionView::Helpers::FormHelper and ActionView::Helpers::JavaScriptMacrosHelper so you get text_field and text_field_with_auto_complete. Another alternative would be to run your built template through ERb again... that might work. Disclaimer: I haven''t tested this code. -- Brad Ediger 866-EDIGERS On Nov 22, 2005, at 4:56 PM, Damon Hill wrote:> Thanks for the replies Jarkko and Torben. > I can now successfully insert rows into my table upon a button click. > However, the next question I have is, can I insert rails code as TD > elements into the table. > > For example, I need to insert the following two elements in the TR > I am inserting: > > <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> > <%= text_field_with_auto_complete :product, :product_name %></td> > > However, whenever I attemp to insert those, I get just the TEXT, > not the functionality of the methods. > > I am using the following to insert the row into the table: > > new Insertion.Bottom(''po_products'', completeRow); > > Obviously, the po_products is my table id, and the complete Row is > the entire string to insert into the HTML. > > Thoughts??? > > Thanks for all the help: > > ~damon > > On 11/22/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > On 22.11.2005, at 21.37, Damon Hill wrote: > > > > > > I attempted this button_to ....:onclick => "addRow()", but it > > appends this to the url ?onclick=addRow(). > > You have the onclick attribute in the url options hash. Try to divide > it up to two hashes and you should be fine. > > //jarkko > > > > > Anyone? Anyone? > > > > Show me just how dumb I am this afternoon. > > It won''t hurt my feelings in the least. > > > > Thanks in advance. > > ~d > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the suggestions Brad. Looks like the easiest way would be to run the built template through ERb again (assuming it works). How would one go about running a dynamically created page back through ERb and not lose the previously added row for the table (in my example at least)? Thanks, ~d On 11/22/05, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote:> > The text_field et al. commands just return their respective HTML. That''s > not working because your completeRow is not processed again by ERb before > hitting the browser. You may have luck with: > completeRow << text_field(...) > ... > new InsertionBottom(''po_products'', completeRow) > > if the code in question is in your view. Otherwise you may have to include > ActionView::Helpers::FormHelper and > ActionView::Helpers::JavaScriptMacrosHelper so you get text_field and > text_field_with_auto_complete. > > Another alternative would be to run your built template through ERb > again... that might work. > > Disclaimer: I haven''t tested this code. > -- > Brad Ediger > 866-EDIGERS > > > On Nov 22, 2005, at 4:56 PM, Damon Hill wrote: > > Thanks for the replies Jarkko and Torben. > I can now successfully insert rows into my table upon a button click. > However, the next question I have is, can I insert rails code as TD > elements into the table. > > For example, I need to insert the following two elements in the TR I am > inserting: > > <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> > <%= text_field_with_auto_complete :product, :product_name %></td> > > However, whenever I attemp to insert those, I get just the TEXT, not the > functionality of the methods. > > I am using the following to insert the row into the table: > > new Insertion.Bottom(''po_products'', completeRow); > > Obviously, the po_products is my table id, and the complete Row is the > entire string to insert into the HTML. > > Thoughts??? > > Thanks for all the help: > > ~damon > > On 11/22/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > > > > > On 22.11.2005, at 21.37, Damon Hill wrote: > > > > > > > > > I attempted this button_to ....:onclick => "addRow()", but it > > > appends this to the url ?onclick=addRow(). > > > > You have the onclick attribute in the url options hash. Try to divide > > it up to two hashes and you should be fine. > > > > //jarkko > > > > > > > > Anyone? Anyone? > > > > > > Show me just how dumb I am this afternoon. > > > It won''t hurt my feelings in the least. > > > > > > Thanks in advance. > > > ~d > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > > Jarkko Laine > > http://jlaine.net > > http://odesign.fi > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
From glancing at the API docs (http://api.rubyonrails.com/classes/ ActionController/Base.html#M000172), it looks like this might work: current_row = render_to_string(:inline => current_row) The render_to_string gives you a string as a result and the :inline tells it you''re passing in a string rather than a controller / action / id triple. Thus only complete_row is re-processed with ERb. I think you''ll have to use render_to_string in your controller, though, not your view. Not sure if this is what you''re trying to accomplish (I missed the beginning of this thread), but it might work. -- Brad Ediger 866-EDIGERS On Nov 22, 2005, at 7:40 PM, Damon Hill wrote:> Thanks for the suggestions Brad. > > Looks like the easiest way would be to run the built template > through ERb again (assuming it works). > How would one go about running a dynamically created page back > through ERb and not lose the previously added row for the table (in > my example at least)? > > Thanks, > ~d > > On 11/22/05, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote: > The text_field et al. commands just return their respective HTML. > That''s not working because your completeRow is not processed again > by ERb before hitting the browser. You may have luck with: > > completeRow << text_field(...) > ... > new InsertionBottom(''po_products'', completeRow) > > if the code in question is in your view. Otherwise you may have to > include ActionView::Helpers::FormHelper and > ActionView::Helpers::JavaScriptMacrosHelper so you get text_field > and text_field_with_auto_complete. > > Another alternative would be to run your built template through ERb > again... that might work. > > Disclaimer: I haven''t tested this code. > -- > Brad Ediger > 866-EDIGERS > > > On Nov 22, 2005, at 4:56 PM, Damon Hill wrote: > >> Thanks for the replies Jarkko and Torben. >> I can now successfully insert rows into my table upon a button click. >> However, the next question I have is, can I insert rails code as >> TD elements into the table. >> >> For example, I need to insert the following two elements in the TR >> I am inserting: >> >> <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></ >> td> >> <%= text_field_with_auto_complete :product, :product_name %></td> >> >> However, whenever I attemp to insert those, I get just the TEXT, >> not the functionality of the methods. >> >> I am using the following to insert the row into the table: >> >> new Insertion.Bottom(''po_products'', completeRow); >> >> Obviously, the po_products is my table id, and the complete Row is >> the entire string to insert into the HTML. >> >> Thoughts??? >> >> Thanks for all the help: >> >> ~damon >> >> On 11/22/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: >> >> On 22.11.2005, at 21.37, Damon Hill wrote: >> > >> > >> > I attempted this button_to ....:onclick => "addRow()", but it >> > appends this to the url ?onclick=addRow(). >> >> You have the onclick attribute in the url options hash. Try to divide >> it up to two hashes and you should be fine. >> >> //jarkko >> >> > >> > Anyone? Anyone? >> > >> > Show me just how dumb I am this afternoon. >> > It won''t hurt my feelings in the least. >> > >> > Thanks in advance. >> > ~d >> > >> > _______________________________________________ >> > Rails mailing list >> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> > http://lists.rubyonrails.org/mailman/listinfo/rails >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://odesign.fi >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Brad, thanks again for the response. However, here is how I am executing the call that generates the completeRow: <input type="button" value="Add New Product to PO" onClick="javascript:addRow();"> And the javascript addRow in my view looks like: function addRow() { var insertedRow1 = ''<td rowspan=\"2\"><\%text_field(\"purchase_order_detail\", \"quantity\", \"size\"=>5) \%></td>''; var insertedRow2 = ''<td rowspan=\"2\"><\%text_field_with_auto_complete :product, :product_name \%></td>''; var insertedRow3 = ''<td rowspan=\"2\"><input type=\"text\" id=\"description\" size=\"40\"></td>''; var insertedRow4 = ''<td><input type=\"text\" id=\"weight" size=\"10\"></td>''; var insertedRow5 = ''<td><input type=\"text\" id=\"buy_price\" size=\"10\"></td>''; var insertedRow6 = ''<td><input type=\"text\" id=\"sell_price\" size=\"10\"></td>''; var insertedRow7 = ''</tr><tr><td><input type=\"text\" id=\"weight2\" size=\"10\"></td><td> </td><td> </td></tr><br />''; var completeRow = insertedRow1 + insertedRow2 + insertedRow3 + insertedRow4 + insertedRow5 + insertedRow6 + insertedRow7; alert(completeRow); new Insertion.Bottom(''po_products'', completeRow); } So you see, the completeRow is created and then passed into the Insertion.Bottom call in javascript. Therefore, I don''t have th ability to run it through the render_to_string, unless there is some way to take the return of the addRow() and pass THAT through the render_to_string in the same step and the onClick of the input. Thoughts? On 11/22/05, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote:> > From glancing at the API docs ( > http://api.rubyonrails.com/classes/ActionController/Base.html#M000172), it > looks like this might work: > current_row = render_to_string(:inline => current_row) > > The render_to_string gives you a string as a result and the :inline tells > it you''re passing in a string rather than a controller / action / id > triple. Thus only complete_row is re-processed with ERb. I think you''ll have > to use render_to_string in your controller, though, not your view. > > Not sure if this is what you''re trying to accomplish (I missed the > beginning of this thread), but it might work. > > -- > Brad Ediger > 866-EDIGERS > > > On Nov 22, 2005, at 7:40 PM, Damon Hill wrote: > > Thanks for the suggestions Brad. > > Looks like the easiest way would be to run the built template through ERb > again (assuming it works). > How would one go about running a dynamically created page back through ERb > and not lose the previously added row for the table (in my example at > least)? > > Thanks, > ~d > > On 11/22/05, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote: > > > > The text_field et al. commands just return their respective HTML. That''s > > not working because your completeRow is not processed again by ERb before > > hitting the browser. You may have luck with: > > completeRow << text_field(...) > > ... > > new InsertionBottom(''po_products'', completeRow) > > > > if the code in question is in your view. Otherwise you may have to > > include ActionView::Helpers::FormHelper and > > ActionView::Helpers::JavaScriptMacrosHelper so you get text_field and > > text_field_with_auto_complete. > > > > Another alternative would be to run your built template through ERb > > again... that might work. > > > > Disclaimer: I haven''t tested this code. > > -- > > Brad Ediger > > 866-EDIGERS > > > > > > On Nov 22, 2005, at 4:56 PM, Damon Hill wrote: > > > > Thanks for the replies Jarkko and Torben. > > I can now successfully insert rows into my table upon a button click. > > However, the next question I have is, can I insert rails code as TD > > elements into the table. > > > > For example, I need to insert the following two elements in the TR I am > > inserting: > > > > <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> > > <%= text_field_with_auto_complete :product, :product_name %></td> > > > > However, whenever I attemp to insert those, I get just the TEXT, not the > > functionality of the methods. > > > > I am using the following to insert the row into the table: > > > > new Insertion.Bottom(''po_products'', completeRow); > > > > Obviously, the po_products is my table id, and the complete Row is the > > entire string to insert into the HTML. > > > > Thoughts??? > > > > Thanks for all the help: > > > > ~damon > > > > On 11/22/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > > > > > > > > On 22.11.2005, at 21.37, Damon Hill wrote: > > > > > > > > > > > > I attempted this button_to ....:onclick => "addRow()", but it > > > > appends this to the url ?onclick=addRow(). > > > > > > You have the onclick attribute in the url options hash. Try to divide > > > it up to two hashes and you should be fine. > > > > > > //jarkko > > > > > > > > > > > Anyone? Anyone? > > > > > > > > Show me just how dumb I am this afternoon. > > > > It won''t hurt my feelings in the least. > > > > > > > > Thanks in advance. > > > > ~d > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > > > Jarkko Laine > > > http://jlaine.net > > > http://odesign.fi > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
There was some talk about a similar application previously on the list. The tread can be found at http://www.ruby-forum.com/topic/10062#3682 This might give you some ideas on how to achieve what your looking for. Cheers On 11/23/05, Damon Hill <mdamonhill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Brad, thanks again for the response. > > However, here is how I am executing the call that generates the > completeRow: > > <input type="button" value="Add New Product to PO" > onClick="javascript:addRow();"> > > And the javascript addRow in my view looks like: > > function addRow() > { > var insertedRow1 = ''<td rowspan=\"2\"><\%> text_field(\"purchase_order_detail\", \"quantity\", \"size\"=>5) \%></td>''; > var insertedRow2 = ''<td rowspan=\"2\"><\%> text_field_with_auto_complete :product, :product_name \%></td>''; > var insertedRow3 = ''<td rowspan=\"2\"><input type=\"text\" > id=\"description\" size=\"40\"></td>''; > var insertedRow4 = ''<td><input type=\"text\" id=\"weight" > size=\"10\"></td>''; > var insertedRow5 = ''<td><input type=\"text\" id=\"buy_price\" > size=\"10\"></td>''; > var insertedRow6 = ''<td><input type=\"text\" id=\"sell_price\" > size=\"10\"></td>''; > var insertedRow7 = ''</tr><tr><td><input type=\"text\" id=\"weight2\" > size=\"10\"></td><td> </td><td> </td></tr><br />''; > > var completeRow = insertedRow1 + insertedRow2 + insertedRow3 + > insertedRow4 + insertedRow5 + insertedRow6 + insertedRow7; > alert(completeRow); > > new Insertion.Bottom(''po_products'', completeRow); > } > > So you see, the completeRow is created and then passed into the > Insertion.Bottom call in javascript. > Therefore, I don''t have th ability to run it through the render_to_string, > unless there is some way to take the return of the addRow() and pass THAT > through the render_to_string in the same step and the onClick of the input. > > Thoughts? > > > > On 11/22/05, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote: > > > > >From glancing at the API docs (http://api.rubyonrails.com/classes/ActionController/Base.html#M000172 > > ), it looks like this might work: > > current_row = render_to_string(:inline => current_row) > > > > The render_to_string gives you a string as a result and the :inline > > tells it you''re passing in a string rather than a controller / action / id > > triple. Thus only complete_row is re-processed with ERb. I think you''ll have > > to use render_to_string in your controller, though, not your view. > > > > Not sure if this is what you''re trying to accomplish (I missed the > > beginning of this thread), but it might work. > > > > -- > > Brad Ediger > > 866-EDIGERS > > > > > > On Nov 22, 2005, at 7:40 PM, Damon Hill wrote: > > > > Thanks for the suggestions Brad. > > > > Looks like the easiest way would be to run the built template through > > ERb again (assuming it works). > > How would one go about running a dynamically created page back through > > ERb and not lose the previously added row for the table (in my example at > > least)? > > > > Thanks, > > ~d > > > > On 11/22/05, Brad Ediger < brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org> wrote: > > > > > > The text_field et al. commands just return their respective HTML. > > > That''s not working because your completeRow is not processed again by ERb > > > before hitting the browser. You may have luck with: > > > completeRow << text_field(...) > > > ... > > > new InsertionBottom(''po_products'', completeRow) > > > > > > if the code in question is in your view. Otherwise you may have to > > > include ActionView::Helpers::FormHelper and > > > ActionView::Helpers::JavaScriptMacrosHelper so you get text_field and > > > text_field_with_auto_complete. > > > > > > Another alternative would be to run your built template through ERb > > > again... that might work. > > > > > > Disclaimer: I haven''t tested this code. > > > -- > > > Brad Ediger > > > 866-EDIGERS > > > > > > > > > On Nov 22, 2005, at 4:56 PM, Damon Hill wrote: > > > > > > Thanks for the replies Jarkko and Torben. > > > I can now successfully insert rows into my table upon a button click. > > > However, the next question I have is, can I insert rails code as TD > > > elements into the table. > > > > > > For example, I need to insert the following two elements in the TR I > > > am inserting: > > > > > > <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> > > > <%= text_field_with_auto_complete :product, :product_name %></td> > > > > > > However, whenever I attemp to insert those, I get just the TEXT, not > > > the functionality of the methods. > > > > > > I am using the following to insert the row into the table: > > > > > > new Insertion.Bottom(''po_products'', completeRow); > > > > > > Obviously, the po_products is my table id, and the complete Row is the > > > entire string to insert into the HTML. > > > > > > Thoughts??? > > > > > > Thanks for all the help: > > > > > > ~damon > > > > > > On 11/22/05, Jarkko Laine < jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: > > > > > > > > > > > > On 22.11.2005, at 21.37, Damon Hill wrote: > > > > > > > > > > > > > > > I attempted this button_to ....:onclick => "addRow()", but it > > > > > appends this to the url ?onclick=addRow(). > > > > > > > > You have the onclick attribute in the url options hash. Try to > > > > divide > > > > it up to two hashes and you should be fine. > > > > > > > > //jarkko > > > > > > > > > > > > > > Anyone? Anyone? > > > > > > > > > > Show me just how dumb I am this afternoon. > > > > > It won''t hurt my feelings in the least. > > > > > > > > > > Thanks in advance. > > > > > ~d > > > > > > > > > > _______________________________________________ > > > > > Rails mailing list > > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > -- > > > > Jarkko Laine > > > > http://jlaine.net > > > > http://odesign.fi > > > > > > > > > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 23.11.2005, at 5.08, Damon Hill wrote:> Brad, thanks again for the response. > > However, here is how I am executing the call that generates the > completeRow: > > <input type="button" value="Add New Product to PO" > onClick="javascript:addRow();"> > > And the javascript addRow in my view looks like: > > function addRow() > { > var insertedRow1 = ''<td rowspan=\"2\"><\%= text_field > (\"purchase_order_detail\", \"quantity\", \"size\"=>5) \%></td>''; > var insertedRow2 = ''<td rowspan=\"2\"><\%= > text_field_with_auto_complete :product, :product_name \%></td>''; > var insertedRow3 = ''<td rowspan=\"2\"><input type=\"text\" id= > \"description\" size=\"40\"></td>''; > var insertedRow4 = ''<td><input type=\"text\" id=\"weight" > size=\"10\"></td>''; > var insertedRow5 = ''<td><input type=\"text\" id=\"buy_price\" > size=\"10\"></td>''; > var insertedRow6 = ''<td><input type=\"text\" id=\"sell_price > \" size=\"10\"></td>''; > var insertedRow7 = ''</tr><tr><td><input type=\"text\" id= > \"weight2\" size=\"10\"></td><td> </td><td> </td></ > tr><br />''; > > var completeRow = insertedRow1 + insertedRow2 + insertedRow3 > + insertedRow4 + insertedRow5 + insertedRow6 + insertedRow7; > alert(completeRow); > > new Insertion.Bottom(''po_products'', completeRow); > } > > So you see, the completeRow is created and then passed into the > Insertion.Bottom call in javascript. > Therefore, I don''t have th ability to run it through the > render_to_string, unless there is some way to take the return of > the addRow() and pass THAT through the render_to_string in the same > step and the onClick of the input. > > Thoughts?The problem is that you are trying to call Rails (=backend) methods on the client side. That is not possible for obvious reasons. If possible, you can make those methods run beforehand so the javascript will not try to insert a ruby method call but the result of that call. From a short look I don''t see why your code couldn''t be executed beforehand. However, if you depend on something that you won''t know before the js call, you need to use AJAX if you need something depending on backend calls. You could easily use AJAX for the kind of thing you''re trying to accomplish. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Sorry - I completely misunderstood you Damon. I thought you were giving me ERb when you were actually using JS. This is what happens when you miss the first half of the thread! Sorry for chasing the rabbit trail. Like Jarkko implied, the helper methods are just an easier method for creating static HTML. It looks like your HTML is going to be static (not dependent on server-side info)--thus, the HTML generated will be the same whenever that button is clicked; it would just add a new row to the PO with the same HTML. In that case, the best option would probably be to throw all that ERb code in a view (temporarily), render it, do a "View Source" on the rendered page, and throw the static HTML in your Javascript code. Thus you would have something like this: var completeRow = ''<td rowspan="2"><input type="text" name="purchase_order_detail[quantity] id="purchase_order_detail_quantity" size="5" /></td><td rowspan="2"> ... ''; However, something like what I recommended earlier might work (though it might violate MVC separation): --(controller) @completeRow = render_to_string(:inline => ''<td...><%= text_field... % ></td>'') --(view) function addRow { var completeRow = ''<%= @completeRow %>''; new Insertion.Bottom(...); } That way would give you the advantage of still having the ERb code in your codebase, but it throws views in your controller, which is kind of ugly. Jarkko is right, though--with JS you''re dealing with client-side code only. If your added row is dependent on runtime data, you''ll need to do an AJAX call or something similar. But Prototype makes that easy... you''d just need an AJAX.Updater. On another note... do you run into problems having the same HTML ID repeated on multiple products? I''m not quite familiar with Insertion.Bottom, but it looks like every Weight field, Description field, and the like would have the same ID. Technically that''s illegal under XHTML, but I don''t know if it will actually cause problems. I remember some thread on the Rails list about ways to deal with this, but I''m not sure what the outcome was. Hope this helps! -- Brad Ediger 866-EDIGERS On Nov 23, 2005, at 3:50 AM, Jarkko Laine wrote:> On 23.11.2005, at 5.08, Damon Hill wrote: > >> Brad, thanks again for the response. >> >> However, here is how I am executing the call that generates the >> completeRow: >> >> <input type="button" value="Add New Product to PO" >> onClick="javascript:addRow();"> >> >> And the javascript addRow in my view looks like: >> >> function addRow() >> { >> var insertedRow1 = ''<td rowspan=\"2\"><\%= text_field >> (\"purchase_order_detail\", \"quantity\", \"size\"=>5) \%></td>''; >> var insertedRow2 = ''<td rowspan=\"2\"><\%= >> text_field_with_auto_complete :product, :product_name \%></td>''; >> var insertedRow3 = ''<td rowspan=\"2\"><input type=\"text\" >> id=\"description\" size=\"40\"></td>''; >> var insertedRow4 = ''<td><input type=\"text\" id=\"weight" >> size=\"10\"></td>''; >> var insertedRow5 = ''<td><input type=\"text\" id=\"buy_price >> \" size=\"10\"></td>''; >> var insertedRow6 = ''<td><input type=\"text\" id=\"sell_price >> \" size=\"10\"></td>''; >> var insertedRow7 = ''</tr><tr><td><input type=\"text\" id= >> \"weight2\" size=\"10\"></td><td> </td><td> </td></ >> tr><br />''; >> >> var completeRow = insertedRow1 + insertedRow2 + >> insertedRow3 + insertedRow4 + insertedRow5 + insertedRow6 + >> insertedRow7; >> alert(completeRow); >> >> new Insertion.Bottom(''po_products'', completeRow); >> } >> >> So you see, the completeRow is created and then passed into the >> Insertion.Bottom call in javascript. >> Therefore, I don''t have th ability to run it through the >> render_to_string, unless there is some way to take the return of >> the addRow() and pass THAT through the render_to_string in the >> same step and the onClick of the input. >> >> Thoughts? > > The problem is that you are trying to call Rails (=backend) methods > on the client side. That is not possible for obvious reasons. If > possible, you can make those methods run beforehand so the > javascript will not try to insert a ruby method call but the result > of that call. From a short look I don''t see why your code couldn''t > be executed beforehand. > > However, if you depend on something that you won''t know before the > js call, you need to use AJAX if you need something depending on > backend calls. You could easily use AJAX for the kind of thing > you''re trying to accomplish. > > //jarkko > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi mdamonhill, can u tell me how u have did that? i m not getting what Jarkko wants to say. I also want to execute a javascript function on onclick of button_to Pls help me, it''s urgent Regards, Pratiksha mdamonhill wrote:> Thanks for the replies Jarkko and Torben. > I can now successfully insert rows into my table upon a button click. > However, the next question I have is, can I insert rails code as TD > elements > into the table. > > For example, I need to insert the following two elements in the TR I am > inserting: > > <%= text_field("purchase_order_detail", "quantity", "size"=>5) %></td> > <%= text_field_with_auto_complete :product, :product_name %></td> > > However, whenever I attemp to insert those, I get just the TEXT, not the > functionality of the methods. > > I am using the following to insert the row into the table: > > new Insertion.Bottom(''po_products'', completeRow); > > Obviously, the po_products is my table id, and the complete Row is the > entire string to insert into the HTML. > > Thoughts??? > > Thanks for all the help: > > ~damon-- 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 -~----------~----~----~----~------~----~------~--~---
> I also want to execute a javascript function on onclick of button_toUse "button_to_function" Rodrigo --~--~---------~--~----~------------~-------~--~----~ 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, If I call a javascript function on clicking a button in RoR, it is appending it to the url. I am not understanding what you meant by " Try to divide it up to two hashes ". Please guide me how to solve this. Thanks. Jarkko Laine wrote:> On 22.11.2005, at 21.37, Damon Hill wrote: >> >> >> I attempted this button_to ....:onclick => "addRow()", but it >> appends this to the url ?onclick=addRow(). > > You have the onclick attribute in the url options hash. Try to divide > it up to two hashes and you should be fine. > > //jarkko-- 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 -~----------~----~----~----~------~----~------~--~---