Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 16c78ca

Browse files
author
Lennon Day-Reynolds
committed
purged all use of find_by_sql (we don't need no steenkin sql)
1 parent f0bc59e commit 16c78ca

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

app/controllers/index_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ class IndexController < ApplicationController
22
def index
33
@upcoming_events = Event.find_upcoming(UPCOMING_EVENT_LIMIT)
44
@recent_events = Event.find_recent(RECENT_EVENT_LIMIT)
5-
@member_articles = Article.find_by_sql "SELECT * FROM articles ORDER BY modified_at DESC LIMIT " + RECENT_ARTICLE_LIMIT.to_s;
5+
@member_articles = Article.find(:all, :limit => RECENT_ARTICLE_LIMIT, :order => 'modified_at DESC')
66
end
77
end

app/models/participant.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def is_attending?
2121
end
2222

2323
def self.find_upcoming(member_id)
24-
# XXX elw: find_all [statement, member_id] or else quote member_id ?
25-
# http://manuals.rubyonrails.com/read/chapter/43
26-
return self.find_by_sql("SELECT * FROM events e, participants p " +
27-
"WHERE p.event_id=e.id AND p.member_id=#{member_id} AND e.starts_at>current_date")
24+
# this is marginally slower than the original find_by_sql call, but doesn't expose
25+
# a huge SQL injection hole, either
26+
self.find(:all, :conditions => ['member_id = ?', member_id]).select do |p|
27+
p.event.starts_at > Time.today
28+
end
2829
end
2930
end

db/test.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)