Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Tutorial for extending and customizing the NUBIC/surveyor gem

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 log
Octocat-spinner-32 public
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 surveys
Octocat-spinner-32 test
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 config.ru
README.md

NUBIC/surveyor gem tutorial for Rails beginners


The NUBIC/surveyor gem is an awesome ruby gem and developer tool that brings surveys into Rails applications. Surveys are written in the Surveyor DSL (Domain Specific Language). If your Rails app needs to asks users questions as part of a survey, quiz, or questionnaire then you should consider using Surveyor.

This tutorial is to help Rails beginners implement and extend this gem in their Rails project. The "kitchen sink" Survey in the surveyor README is a great place to get started, as is the "extending surveyor" README. However, for beginners, I thought it might be useful to have an example that walks through how to tie the surveyor gem to your user model and make some basic customizations. For this tutorial I am using Rails 3.2.3 and Ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0].

Surveyor Tutorial


Section 1 - Create a new rails app with a User model

1) Create a new repository on GitHub named 'surveyor_customize'

2) Create a new rails project

$ rails new surveyor_customize
$ cd surveyor_customize

3) Open the project in your favorite text editor (example: I am using Sublime Text 2)

$ subl .

4) Initialize the Git repository and push to GitHub

$ git init
$ git add .
$ git commit -m "Initial commit"
$ git remote add origin git@github.com:<username>/surveyor_customize.git
$ git push -u origin master

5) (Optional) Deploy the app to Heroku. (Assuming you have already created a Heroku account. If not, check out this tutorial)

$ heroku create --stack cedar
$ git push heroku master

6) Implement chapters 3-9 of Michael Hartl's excellent RoR tutorial

Section 2 - Add the surveyor gem

7) Update the Gemfile. Cut & Paste the contents of this tutorials Gemfile into your Gemfile.

8) Install and include the new gems

$ bundle install

8a) In my case, my rake version is 0.9.2.2 and the surveyor gem requires 0.9.2, so I received the following error:

"You have requested: rake = 0.9.2 The bundle currently has rake locked at 0.9.2.2."

If this happens to you, run the following in your command line:

$ bundle update rake

9) Generate surveyor assets

$ script/rails generate surveyor:install

10) Migrate the database (If you received the rake version error above, be sure to include 'bundle exec' before your rake command)

$ bundle exec rake db:migrate        

11) Try out the 'kitchen sink' survey

$ bundle exec rake surveyor FILE=surveys/kitchen_sink_survey.rb

12) Test it on the local server (start the server)

$ rails s

And visit: http://localhost:3000/surveys

13) Deploy and test it on Heroku

In the production.rb file (located in config/environments) set:

 config.assets.compile = true

Then, in the command line:

$ git add .
$ git commit -am "Installed surveyor assets"
$ git push
$ git push heroku
$ heroku run rake db:migrate
$ heroku run rake surveyor FILE=surveys/kitchen_sink_survey.rb
$ heroku open

Now navigate to http://[yourappname].herokuapp.com/surveys

you can visit the example for this tutorial here: http://surveyor-example.herokuapp.com/surveys

Section 3 - Create your own survey

14) Try making your own survey

Create a new file in the surveys folder of your project, name it 'my_survey.rb' and edit it as you like.

15) Parse the survey

$ bundle exec rake surveyor FILE=surveys/my_survey.rb  

16) Try it on the local server

$ rails s

And visit: http://localhost:3000/surveys

17) Try it on Heroku

$ heroku run rake surveyor FILE=surveys/my_survey.rb
$ heroku open

Now navigate to http://[yourappname].herokuapp.com/surveys

Section 4 - Custmizing Surveyor

18) Generate a sample custom controller and layout

script/rails generate surveyor:custom

Section 5 - show data from my survey in a view

Something went wrong with that request. Please try again.