Skip to content

Instantly share code, notes, and snippets.

@salbito
Created November 24, 2010 15:54
Show Gist options
  • Save salbito/713858 to your computer and use it in GitHub Desktop.
Save salbito/713858 to your computer and use it in GitHub Desktop.
Dynamic Activerelation queries based on attr_accessible
def index
@details = Details.where(["id != ?", 0])
@detail_params = Details.attr_accessible.to_a
for detail_param in @detail_params
if params[detail_param]
@details = @details.where(["#{detail_param} = ?", params[detail_param.intern]])
end
end
@user_ids = @details.select(:user_id).map{|d| d.user_id}
@users = User.find(@user_ids)
respond_with(@users)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment