Skip to content

Instantly share code, notes, and snippets.

@wallace
Created June 29, 2011 05:24
Show Gist options
  • Save wallace/1053211 to your computer and use it in GitHub Desktop.
Save wallace/1053211 to your computer and use it in GitHub Desktop.
# Edit: fixing the SQL injection
class User < ActiveRecord::Base
...
scope :not_a_member_of, lambda { |project_id|
sanitized_join_condition = sanitize_sql_array(
["LEFT OUTER JOIN 'memberships' ON
'memberships'.'user_id' = #{self.quoted_table_name}.'id' AND
'memberships'.'project_id' = ?", project_id]
)
joins(sanitized_join_condition).
where("'memberships'.'project_id' IS NULL")
}
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment