Patrick Shainin wrote:
> 
> For example, to add a check box that limits the search to rows with a 
> certain condition, you could define a named scope in Model.rb like this:
> 
> named_scope :my_condition, :conditions => "your sql condition here"
> 
> Then in the view form, you would include:
> <%= f.label :my_condition, "Check to apply my condition" %>
> <%= f.check_box :my_condition %>

I forgot that f.check_box adds a hidden field so even unchecked, the 
condition will trigger.  One way to get around that is to use lambda in 
the named scope and adjust what condition gets included based on the 
check box value:

named_scope :my_condition, lambda { |check| "1"==check ? {:conditions=> 
"your sql condition here"} : {}}
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to