I'm trying to implement the following functionality. I have a
"has_many" association, let's say User and Phones.
I would like to create/edit Phone numbers while editing/creating a
user. So I have a subform in phones_controller, and my user create/
edit form looks good with phones included in it.
Only one Phone number is primary, so I'm adding a checkbox "Primary"
to the Phone subform (dont' believe it matters, but "is_primary" a
virtual field). If there are multiple phones, any time any "Primary"
box is checked, I'd like to uncheck all the others.
I thought about using subform override  to add an onclick callback to
the checkbox, so I can change the values of the other checkboxes. I'm
trying to follow this doc:
http://wiki.github.com/activescaffold/active_scaffold/subform-form-overrides
So I have app/views/users/_is_primary_form_column.rhtml with this:

<dt><label>Another label</label></dt>
<dd>
<%= check_box("user", "is_primary",
    {:onclick => remote_function(:url  => {:action =>
"on_primary_change"},
    :with => "'is_primary='+value")}, "aha", "nien")
%>
</dd>

and I have on_primary_change method in my users_controller.

"Another label" never appears, so it looks like the override is not
used at all. However, the callback attempts to kick in (although NOT
every time I click on the checkbox), but fails with this:

Processing ApplicationController#index (for 127.0.0.1 at 2009-10-20
17:01:37) [POST]
  Parameters: {"authenticity_token"=>"XXXXXXXXXXXXXXXXXXXXXXX=",
"is_primary"=>"aha"}

ActionController::RoutingError (No route matches "/users/all/
on_primary_change" with {:method=>:post}):
  c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
  c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

Rendering rescues/layout (not_found)

Thanks for your help! Also if you know any other way to implement this
functionality, could you please let me know.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to