#14 ✓resolved

check_box and _is_not_nil

Reported by mollo | October 22nd, 2008 @ 10:00 AM

Hi Ben,

I'm trying check_box tag in form with _is_not_nil condition :

Just put in the view :

= m.check_box :notification_date_is_not_nil

notification_date is a db attribute (DATE)

Params[:search] are correctly mapped :

{"search"=>{"conditions"=>{ "notification_date_is_not_nil"=>"1",

But search fail with this error :

ArgumentError in stuffController#index

wrong number of arguments (0 for 1)

vendor/plugins/searchgasm-1.5.3/lib/searchgasm/condition/not_nil.rb:13:in to_conditions' vendor/plugins/searchgasm-1.5.3/lib/searchgasm/condition/not_nil.rb:13:in to_conditions' vendor/plugins/searchgasm-1.5.3/lib/searchgasm/condition/base.rb:92:in sanitize' ../.. snip

Now for testing I force a condition in the controler :

@search.conditions.notification_date_is_not_nil # No errors, but has no Effect in the query.

and :




Bang with wrong number of arguments (0 for 1)

Who is wrong ? me or searchgasm


Comments and changes to this ticket

  • mollo

    mollo October 23rd, 2008 @ 03:46 AM

    More :

    In fact _not_nil or not_null seem to not work associated with a check_box control.

    but :

     = m.check_box(:notification_date_nil)

    Works! out of the box, without any trick in the controler.

  • Ben Johnson

    Ben Johnson October 23rd, 2008 @ 11:32 AM

    • State changed from “new” to “resolved”

    Yep, thanks for letting me know about this. I fixed this and you should be all set now. Let me know if you have any other issues.

  • mollo

    mollo October 24th, 2008 @ 05:31 AM

    Thanks Ben,

    The error "wrong number of arguments (0 for 1)" is fixed when using _not_nil.

    But still have issues :

    The choice in the check_box is not "saved" in params, but the form keep the unchecked value, even the params[:search][:conditions][:attribute_not_nil]=1.

    Here the 3 possibles situations :

    On first display, params is empty so the search give all the results.

    The search is launched with form's default values : (unchecked box)

    Results : Params : attribute_not_nil: "0" Check box : unchecked Url : &search[conditions][attribute_not_nil]=0 SQL : WHERE ... attribute is NULL)

    Now I check the box, and run the search

    Results: Params : attribute_not_nil: "1" OK Check box : unchecked Url : &search[conditions][attribute_not_nil]=1&search[conditions][attribute_not_nil]=0 SQL : WHERE ... attribute is NULL

    Sorry, but something still wrong.

  • Ben Johnson

    Ben Johnson October 24th, 2008 @ 12:00 PM

    Searchgasm only ignores blank values. 0 is a meaningful value. If rails didn't add in the hidden field all would work fine. But instead you need to set the "unchecked value" to "" or nil.

    search.condition.name_not_nil = 0

    Is basically saying "find records where they are not not nil".

    If you do this:

    f.check_box :name_not_nil, {}, "1", nil

    This will work as expected. I have been thinking about changing this default behavior if the form object is a searchgasm object. But I am hesitant to change rails defaults because it's not what people expect. But this seems to make sense here.

    Let me know if you have any other problems.

  • mollo

    mollo October 25th, 2008 @ 05:00 AM

    Thanks very much Ben.

  • mollo

    mollo October 27th, 2008 @ 09:25 AM

    Hi ben,

    Sorry, but using a custom check_box as you mention, it not work.

    I've sent you (by mail) a sample app for helping you to see the behavior.

    Condensed: Why f.check_box :attrib_not_nil just not work as f.check_box :attrib_nil ?

    Thanks again for your work & efforts!

  • Ben Johnson

    Ben Johnson October 28th, 2008 @ 02:05 AM

    • State changed from “resolved” to “open”
    • Assigned user set to “Ben Johnson”

    I am still working on this. I am adding in some tests and trying to recreate your problem.

  • mollo

    mollo October 30th, 2008 @ 05:47 AM

    Thank you ben,

    It works.

    using f.check_box(:attrib_not_nil,{},"1","") is not needed anymore, a simple f.check_box(:attrib_not_nil) do the job.

  • Ben Johnson

    Ben Johnson October 30th, 2008 @ 11:26 AM

    • State changed from “open” to “resolved”

    Awesome, glad to hear its working out.

  • Pak24tv

    Pak24tv December 9th, 2020 @ 01:26 AM

    I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. zong weekly internet packages how to load zong card

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket