I haven't had time to dig into your problem at length, but naming
local variables 'new' is asking for some disastrous behavior - under
the hood, the ERB that the DRYML compiles to is inside a class. No
idea if that's the issue here, but it can't hurt to rename that
variable.
--Matt Jones
On Jul 18, 2009, at 10:31 PM, Montgomery Kosma wrote:
>
> I have taken this a step closer, basing my second attempt on hobo's
> has-many-checkbox-editor. But still all I get is a spinner and no new
> object created.
>
> The problem seems to be that object_url(new.class, :method => :post)
> is returning nil. new does, in fact, contain the correct object.
>
> Why is that?
>
>
> <def tag="file-set-checkbox-editor" attrs="update, message"><%=
> raise HoboError.new("no update specified") unless update
>
> fields = { "project_id"=> "#...@project_custodian.project.id}",
> "file_set_id" => "#{this.id}" }
> conditions = fields.map{|k,v|"#{k}=#{v}"}.join " AND "
>
> obj = ProjectFileSet.find(:first, :conditions => conditions)
>
> checkbox_attrs = {:type =>'checkbox'}
>
> if obj == nil
> new = ProjectFileSet.new(fields)
> permission = if can_create?(new)
> class_name = new.class.name.underscore
> ajax_options = { :message => message, :spinner_next_to =>
> Hobo.raw_js("this") }
> ajax_options[:params] = { class_name => fields } unless
> fields.empty?
> checkbox_attrs[:onclick] = ajax_updater(object_url
> (new.class, :method => :post), update, ajax_options)
> end
> else
> permission = if can_delete?(obj)
> checkbox_attrs[:checked] = 'checked'
> message ||= "Unsetting #{obj.class.name.titleize}"
> class_name = obj.class.name.underscore
> checkbox_attrs[:onclick] = ajax_updater(object_url(obj, :method
> => :delete), update, {:message => message, :method => 'delete'})
> end
> end
> element(:input, add_classes(attributes.merge(checkbox_attrs),
> "checkbox_input file_set_checkbox")) if
> permission
> %></def>
>
>
>
> On Jul 18, 1:04 pm, Montgomery Kosma <[email protected]> wrote:
>> I have created a nifty page adapting table-plus to show all the
>> datasets for an employee, with a checkbox next to each one that
>> indicates whether that dataset is part of the current project.
>>
>> Last step is getting the checkbox to create or destroy the
>> association
>> object in the join table (ProjectDataSets).
>>
>> I am stuck on where to put in the create / destroy code. Using the
>> debugger, it seems ajax_updater is called only when the page is
>> rendered, not when the checkbox is clicked. But clearly something is
>> happening, since I'm getting a spinner...
>>
>> Here's my tag (based on hobo's boolean-checkbox-editor):
>>
>> <def tag="checkbox-association-editor" attrs="update, message"><%
>> raise HoboError.new("Not allowed to edit") unless can_edit?
>> f = ajax_updater(object_url(this_parent, :method => :put),
>> update,
>> :method => "put",
>> :message => message,
>> :spinner_next_to => Hobo.raw_js("this"),
>> :params => { this_parent.class.name.underscore
>> => {
>> this_field => Hobo.raw_js('this.checked')
>> } })
>> %>
>> <input type="checkbox" value="1" onclick="#{f}" merge-attrs />
>>
>> </def>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---