Created
March 17, 2009 17:38
-
-
Save HamptonMakes/80671 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
make_resourceful do | |
actions :show, :index | |
before :index do | |
@lead_news_item = NewsItem.last | |
end | |
response_for :index do |format| | |
format.html | |
format.json do | |
data = current_objects.collect do |article| | |
"#{article.autocomplete_title}\n" | |
end | |
render :text => data.join | |
end | |
end | |
end | |
private | |
def current_objects | |
sql = "state = ?" | |
data = ["live"] | |
if @search_term = params[:search] | |
sql << " AND published_content LIKE ? " | |
data << "%#{@search_term}%" | |
end | |
if params[:q] | |
sql << " AND title LIKE ? " | |
data << "%#{params[:q]}%" | |
end | |
conditions = [sql] + data | |
@search_count = Article.count(:conditions => conditions ) | |
Article.find(:all, | |
:conditions => conditions, | |
:order => "updated_at DESC", | |
:limit => 20, | |
:include => {:author => :user} | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment