I clicked send button too early. Resent it again, after finish writing it.
On Miércoles, 21 de Octubre de 2009 02:16:27 tuchka escribió: > 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-override >s 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> I think you don't need a remote function if you want to uncheck the other checkboxes. You should use a JavaScript function to get all checkboxes and uncheck them (maybe adding a class to the checkboxes would do easier to get all checkboxes). Also you can use radio_button_tag with is_primary as name, setting the id of each user as the value, and set is_primary in the controller (overriding do_create, in an after_filter or using before_create_save or after_create_save) > > 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) Have you added on_primary_change action to your routes? -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
