I have 2 tables users and roles joined by a users_roles table, writing
the search module to list users according to parameters,
I can easily search on the user.login using :
conditions = ["login LIKE ?", "%#{@params[:qlogin]}%"] unless
@params[:qlogin].nil?
but as I need also to offer a selection on the role, so I am using in
the view :
an- input type="checkbox" name="qrole" id="qrole"
and a - select(“role”, “role_id”, Role.to_dropdown)
can I write :
conditions += [" AND "] unless ( @params[:qlogin].nil? &&
@params[:qrole].nil? )
and
conditions += [“users.role.id = ?”, “#{@params[:role][:role_id]}”]
unless @params[:qrole].nil?
seems quite weird ?
kad