Rails: How to find objects that exceed a certain count -


i trying query want find users have exceed number of violations. in user model each user has_many violation. in index action want find users have more 25 violations. have in users controller:

update

if params[:viewpage] == "violators"     @count = "25".to_i     @users = user.includes(:violation).group('violation.user_id').having("count(*) >= #{@count}").paginate :page => params[:page], :per_page => 20   elsif...... 

this gives me error: invalid value integer(): "violators"

you can use group , having.

user.includes(:violations).group('violations.user_id').having("count(violations.user_id) >= #{@count}") 

of course, if not have control on input, want sanitize input before inject string.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -