questionable_surveys 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -13,6 +13,10 @@ the questions and recording your users' answers.
13
13
 
14
14
  Add Questionable to your Gemfile:
15
15
 
16
+ gem 'questionable_surveys'
17
+
18
+ or for the latest:
19
+
16
20
  gem 'questionable_surveys', :git => 'git://github.com/bespokepost/questionable.git'
17
21
 
18
22
  Then run:
@@ -2,36 +2,7 @@ require_dependency "questionable/application_controller"
2
2
 
3
3
  module Questionable
4
4
  class AnswersController < ApplicationController
5
- respond_to :html, :js
6
-
7
5
  def create
8
- assignment = Assignment.find(params[:assignment_id])
9
-
10
- a = Answer.new
11
- a.assign_attributes({
12
- assignment: assignment,
13
- user: current_user,
14
- option_id: params[:answer][:option_id],
15
- message: (params[:answer][:message] || '')[0..255]
16
- }, without_protection: true)
17
-
18
- if a.save
19
- respond_to do |format|
20
- format.html { redirect_to :back }
21
- format.js { render :text => 'Ok' }
22
- end
23
- else
24
- respond_to do |format|
25
- format.html do
26
- flash[:info] = 'Error saving Answer'
27
- redirect_to :back
28
- end
29
- format.js { render :text => 'Error' }
30
- end
31
- end
32
- end
33
-
34
- def create_multiple
35
6
  answers = params[:answers]
36
7
 
37
8
  if answers.is_a?(Hash)
@@ -49,7 +20,12 @@ module Questionable
49
20
  date = answers.first
50
21
  if date[:year].present? or date[:month].present? or date[:day].present?
51
22
  if date[:year].present? and date[:month].present? and date[:day].present?
52
- assignment.answers.create(user_id: current_user.id, message: "#{date[:year]}-#{date[:month]}-#{date[:day]}")
23
+ answer = assignment.answers.build(user_id: current_user.id, message: "#{date[:year]}-#{date[:month]}-#{date[:day]}")
24
+ if answer.date_answer.nil?
25
+ flash[:warn] = 'Could not save date. Invalid date.'
26
+ else
27
+ answer.save
28
+ end
53
29
  else
54
30
  flash[:warn] = 'Could not save date. You did not select all three fields.'
55
31
  end
@@ -7,20 +7,12 @@ module Questionable
7
7
  belongs_to :option
8
8
  has_one :question, :through => :assignment
9
9
 
10
- =begin
11
- def self.build_answers_for_subject(user, subject)
12
- if subject.kind_of?(Symbol) or subject.kind_of?(String)
13
- assignments = Questionable::Assignment.where(:subject_type => subject)
14
- else
15
- assignments = Questionable::Assignment.where(:subject_type => subject.class.to_s, :subject_id => subject.id)
16
- end
10
+ def date_answer
11
+ return nil if message.nil?
17
12
 
18
- assignments = assignments.order(:position)
19
- assignments.map { |as| as.answers_for_user(user) }
13
+ self.message.to_date
14
+ rescue ArgumentError
15
+ nil
20
16
  end
21
- =end
22
-
23
- # Questionable::Question.joins('INNER JOIN questionable_assignments ON questionable_assignments.question_id = questionable_questions.id').where(:questionable_assignments => { :subject_type => type }).order('questionable_assignments.position')
24
-
25
17
  end
26
18
  end
@@ -1,5 +1,5 @@
1
1
 
2
- = form_tag questionable.answers_create_multiple_path, method: :post, class: 'questions-form' do
2
+ = form_tag questionable.answers_path, method: :post, class: 'questions-form' do
3
3
  - assignments.each do |a|
4
4
  .question-block{:id => "qa_#{a.id}", class: "question-#{a.question.id}"}
5
5
  - q = a.question
@@ -43,7 +43,7 @@
43
43
  =# select_date nil, field, order: [:month, :day, :year]
44
44
  =# date_select (Date.today - 20.years), field, order: [:month, :day, :year]
45
45
 
46
- - date = selected_answers.first.try(:message).blank? ? nil : selected_answers.first.message.to_date
46
+ - date = selected_answers.first.try(:date_answer)
47
47
 
48
48
  .date-fields
49
49
  = select_month date, {prompt: date.blank?}, name: "#{field}[month]", class: 'select-month'
data/config/routes.rb CHANGED
@@ -1,7 +1,3 @@
1
1
  Questionable::Engine.routes.draw do
2
- scope 'assignments/:assignment_id' do
3
- resources :answers, :only => [:create]
4
- end
5
-
6
- post 'answers/create_multiple' => 'answers#create_multiple'
2
+ post 'answers' => 'answers#create'
7
3
  end
@@ -1,3 +1,3 @@
1
1
  module Questionable
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: questionable_surveys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 1.8.23
189
+ rubygems_version: 1.8.25
190
190
  signing_key:
191
191
  specification_version: 3
192
192
  summary: Rails engine that programatically generates surveys.