Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Can I use a check_box to implement a date related search? (i.e. show only expired accounts) #86

Open
theSociableme opened this issue Jan 2, 2012 · 2 comments

Comments

@theSociableme
Copy link

This works fine, however I want to use it as a check box

 <%= f.text_field :user_profile_expiration_lt, :value => Date.today.to_s(:long) %>

if checked then result set contains only where results with expiration less then today.

i.e. Show only expired []

Any ideas how to do this?
or implement a named scope based off of check_box ?

@graywh
Copy link

graywh commented Mar 2, 2012

Use a scope.

class Model < ActiveRecord::Base
  scope :expired, lambda { where(['user_profile_expiration_lt < ?', Date.today]) }
  search_methods :expired
end
<%= f.check_box :expired %>

@gamov
Copy link

gamov commented Dec 21, 2012

I've just been hit by a bug using this method @graywh, if I declare my scope with a lambda, I get the following error:
wrong number of arguments (1 for 0) for scope :with_qty, lambda { where(:id.lt => 100) }
If I remove the lambda, it works: scope :with_qty, where(:id.lt => 100)

To make it work, I need to painfully add a management of the checkbox value, this way:
scope :with_qty, lambda { |cb| cb == '1' ? where(:id.lt => 100) : scoped}
which makes me change all my scopes to manage the checkbox version... very ugly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants