jQuery Branch remove_link Issue

1 view
Skip to first unread message

pimpmaster

unread,
Jun 9, 2008, 7:47:57 AM6/9/08
to attribute_fu
Everything works great with this branch, except when I click the
remove link, it deletes the expected dom element, and when I save the
change is not reflected in DB.. the actualy child model is still there
when I reload.

Any ideas?

James Golick

unread,
Jun 9, 2008, 11:06:16 PM6/9/08
to attrib...@googlegroups.com
sounds like an issue with either removing all the elements from the form, or :discard_if...

could it be either of those?

pimpmaster

unread,
Jun 10, 2008, 3:18:32 PM6/10/08
to attribute_fu
Hmm, i just switched back to good ol' prototype and this is still
buggin, so it rules out the Jquery issue.

Can you see where I went wrong?

class Person < ActiveRecord::Base
has_many :phones, :as => :phoneable, :attributes =>
true, :discard_if => :blank?, :dependent => :destroy
end

class Phone < ActiveRecord::Base
belongs_to :phoneable, :polymorphic => true
def blank?; number.blank?; end
end

pimpmaster

unread,
Jun 10, 2008, 3:50:23 PM6/10/08
to attribute_fu
> sounds like an issue with either removing all the elements from the form

Bingo!

If I have two child objects, it will delete the second one no problem.
But if its just one, att_fu wont delete it.

Is this expected behavior?

James Golick

unread,
Jun 10, 2008, 3:51:23 PM6/10/08
to attrib...@googlegroups.com
ya, you need this line in your controller

params[:parent][:child_attributes] ||= {}

pimpmaster

unread,
Jun 10, 2008, 5:15:42 PM6/10/08
to attribute_fu
Weird.. google groups wont let me post.. posting again:

I tried this:

[new_action,create,edit,update].each do |action|
action.before :destroy_lone_submodels
end

def destroy_lone_submodels
params[:person][:phone_attributes] ||= {}
end

and got this:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

pimpmaster

unread,
Jun 10, 2008, 5:06:37 PM6/10/08
to attribute_fu

James Golick

unread,
Jun 10, 2008, 5:43:39 PM6/10/08
to attrib...@googlegroups.com
params[:person][:phone_attributes] ||= {} unless params[:person].nil?

there won't always be person params

pimpmaster

unread,
Jun 10, 2008, 6:51:50 PM6/10/08
to attribute_fu
That did the trick!

You are pretty good with this code stuff, you should like do it for a
living or something

:p
Reply all
Reply to author
Forward
0 new messages