Caution! - Many of these posts are creepy-old in the Ruby on Rails world (before 1.0!)
The :author => Charles Abbott now blogs here

form_remote_tag revisited

2007-01-07   [ 0 comments ]

The beginning of a new year - and here I am ready to make another post. This post, however, will be short and relatively sweet. Just the other day I decided to use the form_remote_tag as opposed to the simple submit_to_remote - and I quickly realized that I had forgotten its simple syntax.

"How could this be?" - thought I - especially since I had written an article many months ago covering this exact topic! Well, I dived into my small archive of posts here on my site - and found this article submit_to_remote, form_remote_tag, script.aculo.us. So, I took a look and what did I find? Not much concerning form_remote_tag! Shame on me - I notice that I mentioned it was late when I wrote it - so obviously it slipped my mind to cover that topic. So here I am to pick up the slack:

The Ruby on Rails syntax for form_remote_tag in the API is not very clear - and confused me for a few minutes. But after a bit of tinkering around I did get it to work (it would have helped had I found one of my old examples in a previous project!). Here is an example of using form_remote_tag:

<%= form_remote_tag :html => { :class => "myformclass" }, :url => { :action => "new_something" }, :update => "updating", :failure => "alert('Oops, try again.');", :complete => "new Effect.SlideDown('updating');" %>
...Other Form Tags...
<%= submit_tag %>
<%= end_form_tag %>

The html output from the form remote tag looks something like:

<form action="/controller/new_something" class="myformclass" method="post" onsubmit="new Ajax.Updater('new_something', '/controller/new_something', {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.SlideDown('updating');}, onFailure:function(request){alert('Oops, try again.');}, parameters:Form.serialize(this)}); return false;">

So, quite simply, if you wish to add additional html options for your form tag - add them inside the array of values labeled by the :html symbol (of course keep them comma seperated). Example:

:html => { :class => "myformclass", :name => "forthecodeform" }

Then define the action that should receive the Ajax serialized data. If need be you can insert the controller's name as well. Example:

:url => {:controller => "mycontroller", :action => "new_something" }

Then finally include all the options you wish that concern how the Ajax request is handled (seperated by commas). Check the API or review my last post for more info on all the available options.

Well, thats it for today, I plan on posting again concerning a few newer topics and functions from the API before this time next week. Until then, happy coding!

:author => "Charles Abbott"
Converting to Ruby on Rails
 

What?

Who?              Link?



Frameworks Good or Bad?   :date => "2007-10-06"
Where is ForTheCode.com Going?   :date => "2007-09-23"
Refactoring - Vital to Software Development   :date => "2007-09-23"
Mongrel Cluster a quick note - and extra notes   :date => "2007-05-20"
Linux Mongrel and Rails   :date => "2007-05-15"
form_remote_tag revisited   :date => "2007-01-07"
How To: Ubuntu 6.10 Edgy on Rails part 3   :date => "2006-12-30"
How To: Ubuntu 6.10 Edgy on Rails part 2   :date => "2006-12-24"
How To: Ubuntu 6.10 Edgy on Rails   :date => "2006-12-22"
verify ... 5.times do cycle   :date => "2006-09-25"
country_select, country_options_for_select, mail_to   :date => "2006-09-05"
Generate and Send Email in Rails   :date => "2006-08-26"
FDF Model, gsub, and send_data   :date => "2006-08-18"
Active Directory Authentication with acts_as_authenticated   :date => "2006-08-17"
Apache2 proxy with Lighttpd - FastCGI for Rails   :date => "2006-08-08"
reverse! && a simple file Upload Class   :date => "2006-07-29"
send_file - a link to download a file   :date => "2006-07-24"
Environments (production, development, test) and cache_pages   :date => "2006-07-04"
.class .methods .instance_variables   :date => "2006-06-14"
select_tag :multiple => true   :date => "2006-06-01"
FileUtils, action_controller rescues   :date => "2006-05-20"
file_field_tag, File.size, File.path, FileUtils.mv   :date => "2006-05-15"
javascript_include_tag, stylesheet_link_tag   :date => "2006-05-02"
submit_to_remote, form_remote_tag, script.aculo.us   :date => "2006-04-30"
periodically_call_remote, simple_format   :date => "2006-04-26"
observe_field - Ajax!   :date => "2006-04-21"
h method, TextHelper, sanitize(), strip_tags()   :date => "2006-04-15"
Rails API :My API [.count(), link_to, text_area :size]   :date => "2006-04-13"
Rails - HTML Select Tag   :date => "2006-04-05"
Pruning Old Sessions   :date => "2006-03-21"
If Elsif Else, and Searching Too!   :date => "2006-03-17"
SHA1 - A quick update   :date => "2006-03-15"
Initialized! good, Authorized? Great! part 2   :date => "2006-03-11"
Initialized! good, Authorized? Great!   :date => "2006-03-08"
Forms and Routing in RoR   :date => "2006-03-06"
My First RoR Post !   :date => "2006-03-05"