tag:blogger.com,1999:blog-5341928812783456341.post363854158009613850..comments2009-03-17T05:29:49.730-07:00Comments on acts_as_coder: link_to with prompt for rails 2.2.2code-roninhttp://www.blogger.com/profile/15768138906372499564noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-5341928812783456341.post-3469667096967038652009-03-17T05:29:00.000-07:002009-03-17T05:29:00.000-07:00git://github.com/randyinla/link_to_remote_with_pro...git://github.com/randyinla/link_to_remote_with_prompt.git<BR/><BR/>-=Cheers!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-51557212194824170422009-03-17T04:14:00.000-07:002009-03-17T04:14:00.000-07:00I created a simple plugin using script/generate pl...I created a simple plugin using script/generate plugin right after getting it working. Now I'm looking into creating a github account so I can easily include it in future rails projects via the new templates functionality. Will post back here when available.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-84765760812759806692009-03-13T05:41:00.000-07:002009-03-13T05:41:00.000-07:00excellent work randy.. i'm happy to have helped.. ...excellent work randy.. <BR/>i'm happy to have helped.. even if my only function was acts_as_signpost..<BR/><BR/>plugin-izing your code is a pretty straightforward process.. if you grabbed this project from github and spend just a few seconds looking at the code you should see just how simpleBhEdAnAhttps://www.blogger.com/profile/13698870662837790986noreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-8313353507995655412009-03-12T20:34:00.000-07:002009-03-12T20:34:00.000-07:00link_to_remote option:I found a bunch of sites tal...link_to_remote option:<BR/><BR/>I found a bunch of sites talking about using ":with =>" to pass along a prompt request to the link_to_remote prototype helper, but it would still trigger the ajax call whether the field was filled in or not, even if the cancel button was pressed?!? Not good. Using your example as inspiration, I put this in my environment.rb file to override the prototype_helper remote_function method, adding a proper prompt. If I have the time/energy, I'll turn it into my first plugin.<BR/><BR/>(sorry for the format. Not sure your comments allow nice formatted colored code)<BR/><BR/>module ActionView<BR/> module Helpers<BR/> module PrototypeHelper<BR/> def remote_function(options)<BR/> javascript_options = options_for_ajax(options)<BR/><BR/> update = ''<BR/> if options[:update] && options[:update].is_a?(Hash)<BR/> update = []<BR/> update << "success:'#{options[:update][:success]}'" if options[:update][:success]<BR/> update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]<BR/> update = '{' + update.join(',') + '}'<BR/> elsif options[:update]<BR/> update << "'#{options[:update]}'"<BR/> end<BR/><BR/> function = update.empty? ? <BR/> "new Ajax.Request(" :<BR/> "new Ajax.Updater(#{update}, "<BR/><BR/> url_options = options[:url]<BR/> url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)<BR/> function << "'#{escape_javascript(url_for(url_options))}'"<BR/> function << ", #{javascript_options})"<BR/><BR/> function = "#{options[:before]}; #{function}" if options[:before]<BR/> function = "#{function}; #{options[:after]}" if options[:after]<BR/> function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]<BR/> function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]<BR/> function = "var prompt_reply = prompt('#{escape_javascript(options[:prompt])}');if(prompt_reply) { #{function}; }" if options[:prompt]<BR/><BR/> return function<BR/> end<BR/> end<BR/> end<BR/>end<BR/><BR/><BR/>You will need to add the :with option in the view, as in:<BR/>:with => "'your_named_variable_here=' + (prompt_reply)"<BR/><BR/>cancel prompt = no ajax call<BR/>ok button clicked, but blank field = no ajax call<BR/>something in the text field and click ok = ajax call along with your_named_variable = text field value.<BR/><BR/>Thanks again for your post! I never would have figured out where in rails to change it, nor how to simply override it in environment.rb.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-26725235890098841392009-03-11T20:58:00.000-07:002009-03-11T20:58:00.000-07:00Thanks for taking the time to do this and for maki...Thanks for taking the time to do this and for making it available to others!! Inspires me to start doing the same.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-4119748166130778432009-03-01T14:17:00.000-08:002009-03-01T14:17:00.000-08:00nice work, very helpful.nice work, very helpful.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5341928812783456341.post-82649918814042026182009-02-18T12:07:00.000-08:002009-02-18T12:07:00.000-08:00I could have used this back when I created a work ...I could have used this back when I created a work log program for my old company. I instead created a different page for just that action, fortunately I only had a couple of users that needed to be canceled in that time, so it didn't matter too much.Anonymousnoreply@blogger.com