Problem with has_many accessible => true - empty records
Reported by Adam Hoscilo | June 19th, 2009 @ 11:01 AM | in Hobo 1.0 - Final
Description (on hobo 0.8.7):
Category:
has_many :things, :dependent => :destroy, :accessible => true
Thing:
fields do
price :decimal, :precision => 6, :scale => 2
is_active :boolean, :default => true
timestamps
end
belongs_to :category
belongs_to :thing_pattern
has_many :somethings, :accessible => true, :dependent => :destroy
validates_presence_of :price, :thing_pattern #category not validated
<def tag="form" for="Category">
...
<hr/>
<div param="things-forms">
<p><b>Things:</b></p>
<input-many:things>
<div param="card">
<field-list fields="price, thing_pattern"/>
<check-many:somethings/>
</div>
</input-many>
</div>
Problem:
If you hit save on empty form for Category it will show validation
errors on Category and on things. If you remove this
validation:
validates_presence_of :price, :thing_pattern
then save the form for Category with valid data, there will be an empty thing created
Solution:
I have no idea, spent few hours on this in the debugger.
UPDATE:
<check-many:somethings/>
that's the one that
creates the problem if you remove it, everything is fine. in parms
it appears like this: "somethings"=>[""]
Same situation with booleans
Comments and changes to this ticket
-
Adam Hoscilo June 22nd, 2009 @ 04:22 PM
The solution for now is to alter check-many tag by removing:
<input type="hidden" name="#{param_name}[]" value=""/><% # ensure all items are removed when nothing checked %>
There is a problem what to do when you want to remove all somethings (at least one was selected, now you unselect all of them).
-
Bryan Larsen June 23rd, 2009 @ 08:44 PM
- Tag changed from defect to defect, rapid
- Milestone set to Hobo 1.0 - Final
This looks like the same thing as Bug 422. Switch to Rails 2.2 or try moving the hidden input to the bottom of the check-many tag and it should work.
-
Bryan Larsen June 23rd, 2009 @ 09:22 PM
never mind the above statement, it appears to have nothign to do with bug 422.
Try again with
:accessible => true
on yourhas_many :somethings
. -
Adam Hoscilo June 23rd, 2009 @ 11:28 PM
Sorry it's not the exact code from my app, there should be :accessible => true, and there is in my app, my error.
Problem stays.has_many :somethings, :accessible => true, :dependent => :destroy
Rails version is 2.3.2
I solved the problem with boolean by overriting the input tag to look like this (also solves the 2.3 Rails with booleans):
<def tag="input" for="boolean" attrs="name"> <%= unless attributes[:disabled] cb_tag = check_box_tag(name, '1', this, attributes) cb_hidden_tag = hidden_field_tag(name, '') cb_hidden_tag + cb_tag end %> </def> hidden_field_tag(name, '') #was hidden_field_tag(name, '0')
This works on Safari and Firefox on Mac
-
Bryan Larsen October 21st, 2009 @ 02:12 PM
Are there two problems in this ticket? You appear to have two different solutions: modifying check-many and modifying the input for Boolean. Do they both solve the same problem?
(Edit: never mind -- you mention the secondary problem in the last line of your original post). I'll create a separate ticket for the boolean problem.
-
Bryan Larsen October 21st, 2009 @ 02:18 PM
- State changed from new to open
Does this patch (against Hobo 0.8.10) fix your problem?
-
Bryan Larsen October 23rd, 2009 @ 06:28 PM
Don't bother trying the above patch, it will just make things blow up.
I'm having trouble understanding your boolean problem.
My initial understanding was that it had to do with the tri-state nature of boolean variables: If the value was previously "nil", and the user doesn't change it in the form, the new value will be "false". However, in my tests, I get the same behaviour with and without your patch. Am I understanding your boolean problem, or am I out to lunch?
-
Adam Hoscilo October 23rd, 2009 @ 06:38 PM
I'm sorry but I'll have to get back to this after Monday. I reported this problem few months ago and in this moment I don't remember how to reproduce it.
I'm on deadline with some project and don't have time now to check in my code.
Sorry. -
Bryan Larsen October 23rd, 2009 @ 06:51 PM
No problem. I'm just happy you replied at all, given that you reported it in June. I'm having trouble reproducing your first problem, too. We'll take a closer look on Monday.
-
Bryan Larsen November 24th, 2009 @ 10:24 PM
If you hit save on empty form for Category it will show validation errors on Category and on things.
This might be bug #447, which I just fixed.
then save the form for Category with valid data, there will be an empty thing created
If you don't like the empty thing, you can use the hjq-input-many tag from hobo-jquery, or you can help me with bug #542
Same situation with booleans
This looks like #463
I've recreated your snippets here: http://github.com/bryanlarsen/hobo-bug448
Everything appears to work for me. Could you please double check? Thanks.
-
Bryan Larsen December 1st, 2009 @ 08:02 PM
- State changed from open to invalid
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Referenced by
- 470 view_permitted? gets called with no attributes set during create actions #448 and #468 may be related or have more info
- 468 Attributes nil during view_permitted? Ticket #448 could be related.