questionable_surveys 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +93 -0
  3. data/Rakefile +36 -0
  4. data/app/assets/javascripts/questionable/answers.js +2 -0
  5. data/app/assets/javascripts/questionable/application.js +15 -0
  6. data/app/assets/stylesheets/answers.css +29 -0
  7. data/app/assets/stylesheets/questionable.css +13 -0
  8. data/app/controllers/questionable/answers_controller.rb +72 -0
  9. data/app/controllers/questionable/application_controller.rb +5 -0
  10. data/app/helpers/questionable/application_helper.rb +4 -0
  11. data/app/models/questionable/answer.rb +26 -0
  12. data/app/models/questionable/assignment.rb +31 -0
  13. data/app/models/questionable/option.rb +9 -0
  14. data/app/models/questionable/question.rb +29 -0
  15. data/app/views/admin/options/_form.html.haml +8 -0
  16. data/app/views/layouts/questionable/application.html.erb +14 -0
  17. data/app/views/questionable/assignments/_form.html.haml +58 -0
  18. data/config/initializers/questionable.rb +2 -0
  19. data/config/routes.rb +7 -0
  20. data/db/migrate/20130122192903_create_questionable_questions.rb +12 -0
  21. data/db/migrate/20130122193559_create_questionable_assignments.rb +14 -0
  22. data/db/migrate/20130122193820_create_questionable_options.rb +13 -0
  23. data/db/migrate/20130122194315_create_questionable_answers.rb +16 -0
  24. data/lib/questionable.rb +6 -0
  25. data/lib/questionable/admin/answers.rb +19 -0
  26. data/lib/questionable/admin/assignment.rb +24 -0
  27. data/lib/questionable/admin/option.rb +20 -0
  28. data/lib/questionable/admin/question.rb +46 -0
  29. data/lib/questionable/engine.rb +24 -0
  30. data/lib/questionable/version.rb +3 -0
  31. data/lib/questionable_surveys.rb +2 -0
  32. data/lib/tasks/questionable_tasks.rake +4 -0
  33. metadata +193 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Bespoke Post
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,93 @@
1
+ = Questionable
2
+
3
+ Questionable is a Rails engine that make it easier to create and answer surveys through a web interface.
4
+
5
+ You can create your questions and options through the included
6
+ {ActiveAdmin}[https://github.com/gregbell/active_admin] interface.
7
+ If ActiveAdmin is installed in your application, Questionable will automatically add admin pages.
8
+
9
+ Then you can use the included partial template and controller for displaying
10
+ the questions and recording your users' answers.
11
+
12
+ == Installation
13
+
14
+ Add Questionable to your Gemfile:
15
+
16
+ gem 'questionable_surveys', :git => 'git://github.com/bespokepost/questionable.git'
17
+
18
+ Then run:
19
+
20
+ bundle install
21
+ rake questionable:install:migrations
22
+ rake db:migrate
23
+
24
+ Add Questionable to your config/routes.rb:
25
+
26
+ mount Questionable::Engine, :at => 'questions'
27
+
28
+ Optionally add the following to app/assets/stylesheet/application.css:
29
+
30
+ *= require questionable
31
+
32
+ == Usage
33
+
34
+ === Create some questions
35
+
36
+ Create one or more Questions. Supported input_types include select, multiselect,
37
+ radio, checkboxes, date, and string.
38
+
39
+ # input_type may be select, multiselect, radio, checkboxes, or string.
40
+ q = Questionable::Question.create(title: 'What is your favorite color?', input_type: 'select', note: 'This is important')
41
+
42
+ Add Options, unless input_type is 'string'
43
+
44
+ q.options.create(title: 'Red', position: 1)
45
+ q.options.create(title: 'Green', position: 2)
46
+ q.options.create(title: 'Blue', position: 3)
47
+
48
+ Questions must be assigned a 'subject' before they are used.
49
+ They subject can be either an object, via a polymorphic association,
50
+ or something general like "preferences", which we can pass here as a symbol or string.
51
+
52
+ e.g.
53
+
54
+ @product = Product.find(123)
55
+ Questionable::Assignment.create(question_id: q.id, subject: @product)
56
+
57
+ or
58
+
59
+ Questionable::Assignment.create(question_id: q.id, subject_type: 'preferences')
60
+
61
+ === In your controller
62
+
63
+ Here's we fetch question-assignments for a particular symbol:
64
+
65
+ @assignments = Questionable::Assignment.with_subject(:preferences)
66
+
67
+ and here, for a product object:
68
+
69
+ @product = Product.find(params[:id])
70
+ @assignments = Questionable::Assignment.with_subject(@product)
71
+
72
+ === In your view
73
+
74
+ With HAML
75
+
76
+ = render partial: 'questionable/assignments/form', locals: { assignments: @assignments }
77
+
78
+ Or ERB
79
+
80
+ <%= render partial: 'questionable/assignments/form', locals: { assignments: @assignments } %>
81
+
82
+ === Running Tests
83
+
84
+ rake spec
85
+
86
+ == Author
87
+
88
+ Written by {Nick Urban}[https://github.com/nickurban/] at {Bespoke Post}[https://www.bespokepost.com/].
89
+
90
+ == Licence
91
+
92
+ This project uses the MIT-LICENSE.
93
+
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Questionable'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+
33
+ desc "Run all specs in spec directory (excluding plugin specs)"
34
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
35
+ task :default => :spec
36
+
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,29 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .questions-form .note { font-size: 0.8em; }
7
+ .questions-form .question-block { margin-bottom: 20px; }
8
+
9
+ .questions-form .select-month { width: 10em; }
10
+ .questions-form .select-day { width: 4em; }
11
+ .questions-form .select-year { width: 5em; }
12
+
13
+ .questions-form select {
14
+ width: 10em;
15
+ }
16
+
17
+ .questions-form .compact-input {
18
+ vertical-align: top;
19
+ }
20
+
21
+ .questions-form .question-and-note {
22
+ width: 320px;
23
+ }
24
+
25
+ .questions-form .question-and-note,
26
+ .questions-form .compact-input {
27
+ display: inline-block;
28
+ }
29
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,72 @@
1
+ require_dependency "questionable/application_controller"
2
+
3
+ module Questionable
4
+ class AnswersController < ApplicationController
5
+ respond_to :html, :js
6
+
7
+ 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
+ answers = params[:answers]
36
+
37
+ if answers.is_a?(Hash)
38
+ # Answers should always be a hash, and the values should be arrays,
39
+ # even if the question input_type only supports a single answer.
40
+
41
+ answers.each do |assignment_id, answers|
42
+ assignment = Assignment.find(assignment_id)
43
+ assignment.answers.where(user_id: current_user.id).delete_all
44
+
45
+ if assignment.question.input_type == 'string'
46
+ message = answers.first || ''
47
+ assignment.answers.create(user_id: current_user.id, message: message[0..255])
48
+ elsif assignment.question.input_type == 'date'
49
+ date = answers.first
50
+ if date[:year].present? or date[:month].present? or date[:day].present?
51
+ 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]}")
53
+ else
54
+ flash[:warn] = 'Could not save date. You did not select all three fields.'
55
+ end
56
+ end
57
+ else
58
+ option_ids = answers
59
+ option_ids.each do |oid|
60
+ unless oid.blank?
61
+ assignment.answers.create(user_id: current_user.id, option_id: oid)
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+ redirect_to :back
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Questionable
2
+ #class ApplicationController < ActionController::Base
3
+ class ApplicationController < ::ApplicationController
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Questionable
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,26 @@
1
+ module Questionable
2
+ class Answer < ActiveRecord::Base
3
+ attr_accessible :user_id, :assignment_id, :option_id, :message
4
+
5
+ belongs_to :user
6
+ belongs_to :assignment
7
+ belongs_to :option
8
+ has_one :question, :through => :assignment
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
17
+
18
+ assignments = assignments.order(:position)
19
+ assignments.map { |as| as.answers_for_user(user) }
20
+ 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
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Questionable
2
+ class Assignment < ActiveRecord::Base
3
+ attr_accessible :question_id, :subject, :subject_id, :subject_type, :position
4
+
5
+ belongs_to :question
6
+ belongs_to :subject, :polymorphic => true
7
+
8
+ has_many :answers
9
+ has_many :answered_options, :through => :answers, :source => :option
10
+
11
+ def self.with_subject(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
17
+
18
+ assignments.order(:position)
19
+ end
20
+
21
+ def answers_for_user(user)
22
+ self.answers.where(user_id: user.id)
23
+ end
24
+
25
+ # for ActiveAdmin
26
+ def display_name
27
+ "#{self.subject_type}#{self.subject_id}: #{self.question.title}"
28
+ end
29
+
30
+ end # End Assignment
31
+ end
@@ -0,0 +1,9 @@
1
+ module Questionable
2
+ class Option < ActiveRecord::Base
3
+ attr_accessible :note, :position, :question_id, :title, :position
4
+
5
+ belongs_to :question
6
+
7
+ validates_presence_of :title, :question_id
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Questionable
2
+ class Question < ActiveRecord::Base
3
+ has_many :options, :order => 'questionable_options.position ASC'
4
+ has_many :assignments
5
+ has_many :subjects, :through => :assignments
6
+ has_many :answers, :through => :assignments
7
+
8
+ attr_accessible :title, :input_type, :note, :category
9
+
10
+ validates_presence_of :title
11
+
12
+ def accepts_multiple_answers?
13
+ ['checkboxes', 'multiselect'].include?(self.input_type)
14
+ end
15
+
16
+ def answers_for_user(user)
17
+ answers = self.answers.where(user_id: user.id)
18
+ answers.any? ? answers : [self.answers.build(user_id: user.id)]
19
+ end
20
+
21
+ def self.with_subject(subject)
22
+ if subject.kind_of?(Symbol) or subject.kind_of?(String)
23
+ Questionable::Question.joins('INNER JOIN questionable_assignments ON questionable_assignments.question_id = questionable_questions.id').where(:questionable_assignments => { :subject_type => subject }).order('questionable_assignments.position')
24
+ else
25
+ Questionable::Question.joins('INNER JOIN questionable_assignments ON questionable_assignments.question_id = questionable_questions.id').where(:questionable_assignments => { :subject_type => subject.class.to_s, :subject_id => subject.id }).order('questionable_assignments.position')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ = semantic_form_for :questionable_option, url: admin_options_path do |f|
2
+ = f.inputs do
3
+ = f.input(:question_id, :as => :hidden, :input_html => { value: question.id })
4
+ = f.input(:title)
5
+ = f.input(:note)
6
+ = f.input(:position)
7
+ = f.actions
8
+
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Questionable</title>
5
+ <%= stylesheet_link_tag "questionable/application", :media => "all" %>
6
+ <%= javascript_include_tag "questionable/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,58 @@
1
+
2
+ = form_tag questionable.answers_create_multiple_path, method: :post, class: 'questions-form' do
3
+ - assignments.each do |a|
4
+ .question-block{:id => "qa_#{a.id}", class: "question-#{a.question.id}"}
5
+ - q = a.question
6
+
7
+ .question-and-note
8
+ .question= q.title
9
+ .note= q.note if q.note
10
+
11
+ - selected_answers = a.answers_for_user(current_user)
12
+ - selected_option_ids = selected_answers.map(&:option_id)
13
+ - field = "answers[#{a.id}][]"
14
+
15
+ - if q.accepts_multiple_answers?
16
+ / Some inputs can take multiple answers (namely multiselects and checkboxes)
17
+ - if q.input_type == 'checkboxes'
18
+ = hidden_field_tag field
19
+ - q.options.each do |opt|
20
+ %label.checkbox
21
+ = opt.title
22
+ = check_box_tag field, opt.id, selected_option_ids.include?(opt.id)
23
+ - elsif q.input_type == 'multiselect'
24
+ = select_tag field,
25
+ options_from_collection_for_select(q.options, 'id', 'title', selected_option_ids), multiple: true
26
+
27
+ - else
28
+ / Most inputs just take a single answer
29
+ - if q.input_type == 'radio'
30
+ - q.options.each do |opt|
31
+ %label.radio
32
+ = opt.title
33
+ %input{type: :radio, name: field, value: opt.id, checked: selected_option_ids.first == opt.id}
34
+ =# radio_button_tag "answers[#{a.id}][]", opt.id, selected_option_ids.first
35
+ - else
36
+ .compact-input
37
+ - if q.input_type == 'select'
38
+ = select_tag "answers[#{a.id}][]",
39
+ options_from_collection_for_select(q.options, 'id', 'title', selected_option_ids.first), prompt: 'Choose an option'
40
+ - elsif q.input_type == 'string'
41
+ = text_field_tag field, selected_answers.first.try(:message)
42
+ - elsif q.input_type == 'date'
43
+ =# select_date nil, field, order: [:month, :day, :year]
44
+ =# date_select (Date.today - 20.years), field, order: [:month, :day, :year]
45
+
46
+ - date = selected_answers.first.try(:message).blank? ? nil : selected_answers.first.message.to_date
47
+
48
+ .date-fields
49
+ = select_month date, {prompt: date.blank?}, name: "#{field}[month]", class: 'select-month'
50
+ = select_day date, {prompt: date.blank?}, name: "#{field}[day]", class: 'select-day'
51
+ = select_year date,
52
+ {prompt: date.blank?, start_year: (Date.today-13.years).year, end_year: (Date.today-70.years).year},
53
+ name: "#{field}[year]", class: 'select-year'
54
+
55
+ .form-actions
56
+ - label = local_assigns.has_key?(:submit_label) ? submit_label : 'Save'
57
+ = submit_tag label, class: 'btn'
58
+
@@ -0,0 +1,2 @@
1
+ Questionable.user_class = 'User'
2
+ Questionable.current_user_method = 'current_user'
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
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'
7
+ end
@@ -0,0 +1,12 @@
1
+ class CreateQuestionableQuestions < ActiveRecord::Migration
2
+ def change
3
+ create_table :questionable_questions do |t|
4
+ t.string :category
5
+ t.string :title
6
+ t.string :note
7
+ t.string :input_type # string, select, radio, checkboxes, multiselect, etc. statement (checkbox)
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateQuestionableAssignments < ActiveRecord::Migration
2
+ def change
3
+ create_table :questionable_assignments do |t|
4
+ t.integer :question_id
5
+ t.integer :subject_id
6
+ t.string :subject_type
7
+ t.integer :position
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :questionable_assignments, [:subject_type, :subject_id, :position], :name => 'index_questionable_assignments_on_subject_and_position'
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class CreateQuestionableOptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :questionable_options do |t|
4
+ t.integer :question_id
5
+ t.string :title
6
+ t.string :note
7
+ t.integer :position
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :questionable_options, [:question_id, :position]
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class CreateQuestionableAnswers < ActiveRecord::Migration
2
+ def change
3
+ create_table :questionable_answers do |t|
4
+ t.integer :user_id
5
+ t.integer :assignment_id
6
+ t.integer :option_id # which option was chosen as the answer
7
+ t.string :message # a freeform message e.g. "Other"
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :questionable_answers, :user_id
13
+ add_index :questionable_answers, :assignment_id
14
+ add_index :questionable_answers, :option_id
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ require "questionable/engine"
2
+
3
+ module Questionable
4
+ mattr_accessor :user_class
5
+ mattr_accessor :current_user_method
6
+ end
@@ -0,0 +1,19 @@
1
+ if defined?(ActiveAdmin)
2
+ ActiveAdmin.register Questionable::Answer, :as => 'Answers' do
3
+ menu :label => 'Answers', :parent => 'Questionable'
4
+
5
+ filter :user_email, :as => :string
6
+ filter :assignment_sources
7
+ filter :created_at
8
+ filter :updated_at
9
+
10
+ index do
11
+ column(:id) { |a| link_to a.id, admin_answer_path(a) }
12
+ column(:user)
13
+ column(:assignment)
14
+ column(:option)
15
+ column(:message)
16
+ default_actions
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ if defined?(ActiveAdmin)
2
+ ActiveAdmin.register Questionable::Assignment, :as => 'Assignments', :sort_order => 'source_type, source_id, position' do
3
+ menu :label => 'Assignments', :parent => 'Questionable'
4
+
5
+ index do
6
+ column(:id) { |a| link_to a.id, admin_assignment_path(a.id) }
7
+ column(:subject) { |a| a.subject_id ? a.subject : a.subject_type }
8
+ column :position
9
+ column(:question) { |a| a.question.title }
10
+ column :created_at
11
+ column :updated_at
12
+ end
13
+
14
+ form do |f|
15
+ f.inputs do
16
+ f.input :question
17
+ f.input :subject_type
18
+ f.input :subject_id, :as => :number
19
+ f.input :position
20
+ end
21
+ f.actions
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ if defined?(ActiveAdmin)
2
+ # NOTE: This ":as" option determines the names of the routes generated
3
+ ActiveAdmin.register Questionable::Option, :as => 'Options' do
4
+ menu :label => 'Options', :parent => 'Questionable'
5
+
6
+ controller do
7
+ def create
8
+ create!(location: request.referrer)
9
+ end
10
+
11
+ def update
12
+ update!(location: admin_question_path(resource.question))
13
+ end
14
+
15
+ def destroy
16
+ destroy!(location: admin_question_path(resource.question))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ if defined?(ActiveAdmin)
2
+ # NOTE: This ":as" option determines the names of the routes generated
3
+ ActiveAdmin.register Questionable::Question, :as => 'Questions' do
4
+ menu :label => 'Questions', :parent => 'Questionable'
5
+
6
+ form do |f|
7
+ f.inputs do
8
+ f.input :title
9
+ f.input :note
10
+ f.input :category
11
+ f.input :input_type, :as => :select,
12
+ :collection => %w(select radio checkboxes multiselect date string statement), :include_blank => false
13
+ end
14
+ f.actions
15
+ end
16
+
17
+ show do |q|
18
+ attributes_table do
19
+ row :id
20
+ row :title
21
+ row :note
22
+ row :category
23
+ row :input_type
24
+ end
25
+
26
+ panel 'Options', class: 'options' do
27
+ table_for(q.options) do
28
+ column(:id) { |o| link_to o.id, admin_option_path(o) }
29
+ column :title
30
+ column :note
31
+ column :position
32
+ column(:actions) do |o|
33
+ link_to('Edit', edit_admin_option_path(o)) + ' | ' +
34
+ link_to('Delete', admin_option_path(o), :method => :delete)
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ panel 'Add Option', class: 'add-option' do
41
+ render partial: 'admin/options/form', locals: { question: q }
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,24 @@
1
+ require 'stringex'
2
+
3
+ module Questionable
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Questionable
6
+
7
+ initializer :questionable do
8
+ if defined?(ActiveAdmin)
9
+ dir = File.dirname(__FILE__) + '/admin'
10
+ # Prepend the load paths, which should allow this to be overridden by an app.
11
+ # If we wanted to prevent an override, we could append dir to load_paths instead.
12
+ ActiveAdmin.application.load_paths.unshift dir
13
+ #ActiveAdmin.application.load_paths += dir
14
+ end
15
+ end
16
+
17
+ config.generators do |g|
18
+ g.test_framework :rspec, :view_specs => false, :fixture => false
19
+ g.fixture_replacement :factory_girl, :dir => "spec/factories"
20
+ g.assets false
21
+ g.helper false
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Questionable
2
+ VERSION = "0.1.6"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "questionable"
2
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :questionable do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: questionable_surveys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Urban
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: haml
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: formtastic
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: stringex
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: factory_girl_rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Makes it easy to add and edit forms programatically, specifying select,
127
+ radio, checkbox, or string input, and recordings users' answers. Questions can be
128
+ associated with specific objects or with string labels. A form template and controller
129
+ are including for displaying questions and recording answers, and ActiveAdmin is
130
+ supported for editing the questions and options on the back-end.
131
+ email:
132
+ - nick@nickurban.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - app/assets/javascripts/questionable/answers.js
138
+ - app/assets/javascripts/questionable/application.js
139
+ - app/assets/stylesheets/answers.css
140
+ - app/assets/stylesheets/questionable.css
141
+ - app/controllers/questionable/answers_controller.rb
142
+ - app/controllers/questionable/application_controller.rb
143
+ - app/helpers/questionable/application_helper.rb
144
+ - app/models/questionable/answer.rb
145
+ - app/models/questionable/assignment.rb
146
+ - app/models/questionable/option.rb
147
+ - app/models/questionable/question.rb
148
+ - app/views/admin/options/_form.html.haml
149
+ - app/views/layouts/questionable/application.html.erb
150
+ - app/views/questionable/assignments/_form.html.haml
151
+ - config/initializers/questionable.rb
152
+ - config/routes.rb
153
+ - db/migrate/20130122192903_create_questionable_questions.rb
154
+ - db/migrate/20130122193559_create_questionable_assignments.rb
155
+ - db/migrate/20130122193820_create_questionable_options.rb
156
+ - db/migrate/20130122194315_create_questionable_answers.rb
157
+ - lib/questionable/admin/answers.rb
158
+ - lib/questionable/admin/assignment.rb
159
+ - lib/questionable/admin/option.rb
160
+ - lib/questionable/admin/question.rb
161
+ - lib/questionable/engine.rb
162
+ - lib/questionable/version.rb
163
+ - lib/questionable.rb
164
+ - lib/questionable_surveys.rb
165
+ - lib/tasks/questionable_tasks.rake
166
+ - MIT-LICENSE
167
+ - Rakefile
168
+ - README.rdoc
169
+ homepage: https://github.com/bespokepost/questionable
170
+ licenses: []
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 1.8.23
190
+ signing_key:
191
+ specification_version: 3
192
+ summary: Rails engine that programatically generates surveys.
193
+ test_files: []