进行动态调查应该很简单!
One stop solution for all survey related requirements! Its tad easy!
This gem supports:
NOTE: Some combinations won't be supported. Please check CI for the ignored ones.
A simple implementaiton of this gem can be found at https://rapidfire.fly.dev. And the source code of application is https://github.com/code-mancers/rapidfire-app.
Add this line to application's Gemfile:
gem 'rapidfire'And then execute:
$ bundle install
$ bundle exec rake rapidfire:install:migrations
$ bundle exec rake db:migrateRapidfire views can also be customized. This command copies the views into app/views directory:
$ bundle exec rails generate rapidfire:viewsRapidfire locales (i18n) files can also be customized. The command is:
$ bundle exec rails generate rapidfire:localesAdd this line to config/routes.rb file, thats good enough
mount Rapidfire::Engine => "/rapidfire"Please point the browser to http://localhost:3000/rapidfire
All rapidfire controllers inherit from your ApplicationController. So define 2
methods current_user and can_administer? on your ApplicationController
current_user : the user who is answering the survey. can be nilcan_administer? : a method which determines whether current user can
create/update survey questions.Typical implementation would be:
class ApplicationController /attempts/newThis url can be distributed so that survey takers can attempt the survey
If you have an established application that uses route helpers and/or the
url_for([@model1, @model2]) style, you can include your route helpers in
RapidFire by adding config/initializers/rapidfire.rb with the
following content:
Rails.application.config.after_initialize do
Rails.application.reload_routes!
Rapidfire::ApplicationController.class_eval do
main_app_methods = Rails.application.routes.url_helpers.methods
main_app_route_methods = main_app_methods.select{|m| m =~ /_url$/ || m =~ /_path$/ }
main_app_route_methods.each do |m|
define_method m do |*args|
main_app.public_send(m, *args)
end
helper_method m
end
end
endThere is an API for fetching the results. This is not efficient, but is provided for the sake of quickly aggregating survey results
GET /rapidfire/surveys//resultsThis new api supports two formats: html and json. The json format can be used with any
javascript based chart solutions like Chart.js. An example can be seen
here.
Diving into details of json format, all the questions can be categorized into
one of the two categories:
All the aggregatable answers will be returned in the form of hash, and the non-aggregatable answers will be returned in the form of an array. A typical json output will be like this:
…This gem gives on the fly access to create questions under a survey. Once the survey is created, questions can be added to the survey. Every survey will have a url which can be can passed around to others to take the survey.
The typical flow about how to use this gem is:
Create a survey by giving it a name.
Once the survey is created, start adding questions to the survey
Create a question by clicking on add new, and there will be several options Each question will have a type
answer options field. Note that each option
should be on a separate line.Once the type is filled, optionally other details can be filled:
Once the questions are populated, a url will be created which can be shared
Note that answers fail to persist if the criteria provided while creating the questions fail.
$ rake rapidfire:upgrade:migrations:multitenancySome table names have changed:
rapidfire_question_groups to rapidfire_surveys, andrapidfire_answer_groups to rapidfire_attempts.Run this rake task to do this change automatically
$ rake rapidfire:upgrade:migrations:from210to300The default delimiter which is used to store options for questions like select input, multiple answers for checkbox question is comma (,). This resulted in problems where gem is unable to parse options properly if answers also contain commas. For more information see issue-19.
Starting from version 2.0.0 default delimiter is changed to \r\n, but a
configuration is provided to change the delimiter. Please run this rake task
to make existing questions or stored answers to use new delimiter.
NOTE: Please take database backup before running this rake task.
bundle exec rake rapidfire:change_delimiter_from_comma_to_srsn
bundle exec rake rapidfire:change_delimiter_from_comma_to_srsnIf this change is not feasible rightaway, and the application needs to use comma
as delimiter, then please use this initializer, but be warned that in future
delimiter will be hardcoded to \r\n:
# //config/initializers/rapidfire.rb
Rapidfire.config do |config|
config.answers_delimiter = ','
endgit checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)暂无开放 Issues,或尚未同步最近议题。