Permalink
Browse files

Anonymous surveys works

  • Loading branch information...
mark-d-holmberg committed Apr 11, 2012
1 parent 91b1f91 commit 49e4757ed00d0372d3257e3cbcab508a65b0bea3
@@ -17,7 +17,7 @@
* {
margin: 0 auto;
padding: 0em;
- text-align: justify;
+ text-align: left;
font-family: "Arial", "Helvetica", "Sans-Serif";
z-index: -1;
}
@@ -1,17 +1,14 @@
class SurveysController < ApplicationController
-#before_filter :authorize
load_and_authorize_resource
+
def index
-#@surveys = Survey.all
end
def show
-#@survey = Survey.find(params[:id])
end
#SPEC: 2.2.2: Adding a new Survey(form)
def new
-#@survey = Survey.new
3.times do
question = @survey.questions.build
4.times { question.answers.build }
@@ -20,7 +17,6 @@ def new
#SPEC: 2.2.5: Create a new Survey(form)
def create
-#@survey = Survey.new(params[:survey])
if @survey.save
redirect_to @survey, :notice => "Successfully created survey."
else
@@ -30,14 +26,12 @@ def create
#SPEC: 2.2.4: Edit an existing Survey(form)
def edit
-#@survey = Survey.find(params[:id])
end
#SPEC: 2.2.7: Update the DB with the new Survey(form)
def update
-#@survey = Survey.find(params[:id])
if @survey.update_attributes(params[:survey])
- redirect_to @survey, :notice => "Successfully updated survey."
+ redirect_to @survey
else
render :action => 'edit'
end
@@ -46,7 +40,6 @@ def update
#SPEC: 2.2.3: Removing an existing Survey(form)
#SPEC: 2.2.9: Destroy an existing Survey(form)
def destroy
-#@survey = Survey.find(params[:id])
@survey.destroy
redirect_to surveys_url, :notice => "Successfully destroyed survey."
end
View
@@ -7,10 +7,11 @@
# content :text
# created_at :datetime not null
# updated_at :datetime not null
+# anonymous :boolean(1) default(FALSE)
#
class Question < ActiveRecord::Base
- attr_accessible :content, :answers_attributes
+ attr_accessible :content, :answers_attributes, :anonymous
belongs_to :survey
has_many :answers, :dependent => :destroy
View
@@ -8,9 +8,11 @@
# updated_at :datetime not null
# published :boolean(1) default(FALSE)
# available_at :datetime
+# anonymous :boolean(1) default(FALSE)
#
class Survey < ActiveRecord::Base
+ after_save :check_anonymous
attr_accessible :name, :published, :available_at, :questions_attributes, :anonymous
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions,
@@ -28,4 +30,20 @@ class Survey < ActiveRecord::Base
def my_questions
self.questions.map(&:id)
end
+
+ def my_anonymous_questions
+ questions.where(:anonymous => true)
+ end
+
+ def my_public_questions
+ questions.where(:anonymous => false)
+ end
+
+ def check_anonymous
+ if anonymous == true
+ questions.each { |question| question.update_attributes(:anonymous => true) }
+ else
+ questions.each { |question| question.update_attributes(:anonymous => false) }
+ end
+ end
end
@@ -17,7 +17,9 @@
</div>
<div class="field anonymous">
- Make Survey Anonymous? <%= f.check_box :anonymous %>
+ Make Survey Anonymous?<br />
+ Yes: <%= f.radio_button :anonymous, true %>
+ No: <%= f.radio_button :anonymous, false %>
</div>
<div class="field">
@@ -38,7 +38,7 @@
<tr>
<td><%= markdown "**Published?: #{@survey.published}**" %></td>
<td><%= markdown "**Available On: #{@survey.available_at}**" %></td>
- <td><%= markdown "**Anonymous Survey?: #{@survey.anonymous}**" %></td>
+ <td><%= markdown "**Anonymous?: #{@survey.anonymous}**" %></td>
</tr>
</table>
</section>

0 comments on commit 49e4757

Please sign in to comment.