Skip to content

Commit

Permalink
[codeforamerica#18] Fixed style and formatting for controllers
Browse files Browse the repository at this point in the history
* Tabs are whitspace
* Indentation is correct
* Fixed the styling inconsistencies I noticed.
  • Loading branch information
Philip Hale committed Sep 1, 2013
1 parent 2caf1c0 commit c92f600
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ArticlesController < ApplicationController

# GET /articles
# GET /articles.json

def index
@bodyclass = "results"

Expand Down
9 changes: 5 additions & 4 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
class CategoriesController < ApplicationController
def index
@bodyclass = "results"
@bodyclass = "results"

@categories = Category.by_access_count
respond_to do |format|
format.html # index.html.erb
format.json { render json: @categories }
end
end

def show
return render(:template => 'categories/missing') unless Category.exists? params[:id]
return render(:template => 'categories/missing') unless Category.exists? params[:id]

@category = Category.find(params[:id])
# redirection of old permalinks
if request.path != category_path( @category )
if request.path != category_path(@category)
logger.info "Old permalink: #{request.path}"
return redirect_to @category, status: :moved_permanently
end

@category.delay.increment! :access_count

@content_html = BlueCloth.new(@category.name).to_html
@bodyclass = "results"

Expand Down
1 change: 0 additions & 1 deletion app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ def show
end
end


end
4 changes: 2 additions & 2 deletions app/controllers/guides_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def show

return render(:template => 'articles/missing') unless @article.published?
#redirection of old permalinks
if request.path != guide_path( @article )
if request.path != guide_path(@article)
logger.info "Old permalink: #{request.path}"
return redirect_to @article, status: :moved_permanently
end
Expand All @@ -24,7 +24,7 @@ def show
render :show_html and return
end

@content_main = @article.md_to_html( @article.content )
@content_main = @article.md_to_html(@article.content)

respond_to do |format|
format.html # show.html.erb
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
@popular_categories = Category.by_access_count.limit(3)
end

def about
end
def about
end

end
14 changes: 7 additions & 7 deletions app/controllers/quick_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ class QuickAnswersController < ApplicationController

def show
return render(:template => 'articles/missing') unless QuickAnswer.exists? params[:id]

@article = QuickAnswer.find(params[:id])

# refuse to display unpublished articles
return render(:template => 'articles/missing') unless @article.published?

#redirection of old permalinks
if request.path != quick_answer_path( @article )
if request.path != quick_answer_path(@article)
logger.info "Old permalink: #{request.path}"
return redirect_to @article, :status => :moved_permanently
end

# basic statistics on how many times an article has been accessed
@article.delay.increment! :access_count
@article.delay.category.increment!(:access_count) if @article.category
Expand All @@ -24,9 +24,9 @@ def show
render :show_html and return
end

@content_main = @article.md_to_html( :content_main )
@content_main_extra = @article.md_to_html( :content_main_extra )
@content_need_to_know = @article.md_to_html( :content_need_to_know )
@content_main = @article.md_to_html(:content_main)
@content_main_extra = @article.md_to_html(:content_main_extra)
@content_need_to_know = @article.md_to_html(:content_need_to_know)

respond_to do |format|
format.html # show.html.erb
Expand Down
19 changes: 14 additions & 5 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
class SearchController < ApplicationController
def index
query = params[:q].strip
return redirect_to root_path if params[:q].blank?
return redirect_to root_path if params[:q].blank?
query = params[:q].strip
@query = query
# spell check the query.

# spell check the query.
@query_corrected = Article.spell_check query

# remove puntuation and plurals.
query = query.downcase.gsub(/[^\w]/, ' ').gsub(/ . /, ' ')

# remove stop words
query = Article.remove_stop_words query
# Searchify can't handle requests longer than this (because of query expansion + Tanker inefficencies. >10 can result in >8000 byte request strings)

# Searchify can't handle requests longer than this (because of query
# expansion + Tanker inefficencies. >10 can result in >8000 byte request
# strings)
if query.split.size > 10 || query.blank?
@query_corrected = query
@results = []
return
end

# expand the query
query_final = Article.expand_query( query )
query_final = Article.expand_query(query)

# perform the search
@results = Article.search(query_final)

# Log the search results
puts "search-request: IP:#{request.env['REMOTE_ADDR']}, params[:query]:#{query}, QUERY:#{query_final}, FIRST_RESULT:#{@results.first.title unless @results.empty?}, RESULTS_N:#{@results.size}"

Expand Down
18 changes: 8 additions & 10 deletions app/controllers/web_services_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class WebServicesController < ApplicationController

def show
return render(:template => 'articles/missing') unless WebService.exists? params[:id]

@article = WebService.find(params[:id])

# refuse to display unpublished articles
return render(:template => 'articles/missing') unless @article.published?

#redirection of old permalinks
if request.path != web_service_path( @article )
if request.path != web_service_path(@article)
logger.info "Old permalink: #{request.path}"
return redirect_to @article, status: :moved_permanently
end
Expand All @@ -24,16 +24,14 @@ def show
render :show_html and return
end

@content_main = @article.md_to_html( :content_main )
@content_main_extra = @article.md_to_html( :content_main_extra )
@content_need_to_know = @article.md_to_html( :content_need_to_know )

@content_main = @article.md_to_html(:content_main)
@content_main_extra = @article.md_to_html(:content_main_extra)
@content_need_to_know = @article.md_to_html(:content_need_to_know)

respond_to do |format|
format.html # show.html.erb
format.json { render json: @article }
end
end
end
end


end

0 comments on commit c92f600

Please sign in to comment.