form_for and onSubmit()
By chris on February 26th 2007 in /dev/rails | 734 views
The syntax for creating forms with Javascript onSubmit() events using the new form_for tag is not readily apparent so:
RUBY:
-
<% form_for :user_group, :url => { :controller => :user_group, :action => :new }, :html => { :onsubmit => "return validate_user_fields( this );" } do |form| %>
(Yes, the use of :controller => :user_group is redundant since Rails can infer the controller from the context of the current controller but I like the readability of it. It helps solves the "'What the heck is this really supposed to do?' six months from now" question quite handily.)
