diff --git a/anne-survey.rb b/anne-survey.rb index c7a6e22..851f6d1 100644 --- a/anne-survey.rb +++ b/anne-survey.rb @@ -13,6 +13,10 @@ module Anne include Camping::Session secret "JeMoeder" + def self.create + Anne::Models.create_schema + end + end module Anne::Models @@ -49,14 +53,16 @@ end module Anne::Helpers def next_image - all_images = Pathname.glob(IMAGE_DIR + "*.jpg").map { |img| - img.basename.to_s } - voted_images = Anne::Models::Vote.find(:all, :conditions => { - :user_id => @state["user"].id }).map { |vote| vote.image } + all_images = + Pathname.glob(IMAGE_DIR + "*.jpg").map { |img| img.basename.to_s } + all_votes = + Anne::Models::Vote.find(:all, + :conditions => { :user_id => @state["user"].id }) + voted_images = all_votes.map { |vote| vote.image } remaining_images = all_images - voted_images return nil, 100 if remaining_images.empty? - return remaining_images.sort_by { rand }.first, 100 - - (remaining_images.length * 100.0 / all_images.length).to_i + return remaining_images.sort_by { rand }.first, + 100 - (remaining_images.length * 100.0 / all_images.length).to_i end end @@ -97,7 +103,7 @@ module Anne::Controllers def post choice = if @input.left then "left" elsif @input.right then "right" - else "either" + else raise "no choice made!" end vote = Anne::Models::Vote.create( :user_id => @state["user"].id, :image => @input.image, @@ -124,6 +130,16 @@ module Anne::Controllers return redirect Vote unless next_image.first.nil? render :finish end + + def post + user = User.find(@state["user"].id) + raise "unknown user" if user.nil? + user.email = @input.email + user.prize = !@input.prize.nil? + user.results = !@input.results.nil? + user.save + redirect Thanks + end end class Style < R '/style\.css' @@ -135,6 +151,12 @@ module Anne::Controllers end end + class Thanks + def get + render :thanks + end + end + end module Anne::Views @@ -143,7 +165,6 @@ module Anne::Views xhtml_strict do head do title "Anne's hippe enqueteshizzle" - p @state["user"].inspect link :rel => "stylesheet", :type => "text/css", :media => "screen", :href => "/style.css" end @@ -181,8 +202,8 @@ module Anne::Views make_select "Studiejaar", "user_study_year", ["nvt"] + (1998..2010).to_a make_select "Geslacht", "user_gender", ["", "man", "vrouw"] make_select "Kleurenblind?", "user_colorblind", ["nee", "ja"] - make_select "Ruimtelijk ingesteld?", "user_spaciousness", ["neutraal", - "ja", "nee"] + make_select "Ruimtelijk ingesteld?", "user_spaciousness", + ["neutraal", "ja", "nee"] input :type => "submit", :value => "Start de enquete" end @@ -222,11 +243,16 @@ module Anne::Views end end -end + def thanks + h2 "Bedankt voor die bloemen!" + end -def Anne.create - Anne::Models.create_schema end __END__ /* Style sheet for the Anne Survey Camping app */ + +body { + color: white; + background-color: black; +}