Skip to content

Commit

Permalink
Refactored code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
agrimm committed Nov 15, 2008
1 parent 0a881b7 commit c4df761
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/controllers/read_controller.rb
Expand Up @@ -2,15 +2,7 @@ class ReadController < ApplicationController

def read
@repository_choices = Repository.find(:all).map {|rc| [rc.short_description, rc.id]}
@default_repository_choice = params[:repository_id].to_i
if params[:repository_id].nil?
hard_wired_preference = "English language Wikipedia"
@repository_choices.each do |short_description, id_number|
if short_description == hard_wired_preference
@default_repository_choice = id_number
end
end
end
@default_repository_choice = determine_default_repository_choice
@markup_choices = [ ["Auto-detect (default)", "auto-detect"], ["MediaWiki formatting", "mediawiki"], ["Plain text", "plain"] ]
if request.post?
@errors = []
Expand Down Expand Up @@ -44,4 +36,21 @@ def read
end
end

private
def determine_default_repository_choice
unless params[:repository_id].nil?
default_repository_choice = params[:repository_id].to_i
else params[:repository_id].nil?
hard_wired_preference = "English language Wikipedia"
@repository_choices.each do |short_description, id_number|
if short_description == hard_wired_preference
default_repository_choice = id_number
end
end
end
return default_repository_choice
end



end
2 changes: 2 additions & 0 deletions app/views/read/read.rhtml
@@ -1,4 +1,6 @@
<% unless @errors.blank? %>
<H1>Errors with input</H1>
<p>The following errors were found:</p>
<ul>
<% for error in @errors %>
<li><p><%= h(error) %></p></li>
Expand Down

0 comments on commit c4df761

Please sign in to comment.