Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Joins syntax updates and removal of unnecessary sanitize_sql call

  • Loading branch information...
commit dacf987d5dfce6f6414477cca70ab37f87265d8b 1 parent 6f09ebb
@rwdaigle authored
View
2  the-skinny-on-scopes-formerly-named-scope/app/models/post.rb
@@ -27,7 +27,7 @@ class << self
# Start with an empty scope and build on it for each attr
def search(q)
[:title, :body].inject(scoped) do |combined_scope, attr|
- combined_scope.where("posts.#{attr} LIKE ?", "%#{sanitize_sql(q)}%")
+ combined_scope.where("posts.#{attr} LIKE ?", "%#{q}%")
end
end
end
View
4 the-skinny-on-scopes-formerly-named-scope/app/models/user.rb
@@ -6,10 +6,10 @@ class User < ActiveRecord::Base
validates_presence_of :username
scope :published, lambda {
- joins("join posts on posts.author_id = users.id").
+ joins(:posts).
where(Post.published.where_values).
group("users.id")
}
- scope :commented, joins("join comments on comments.user_id = users.id").group("users.id")
+ scope :commented, joins(:comments).group("users.id")
end
Please sign in to comment.
Something went wrong with that request. Please try again.