<commit_before># Rapidfire
[![Code Climate](https://codeclimate.com/github/code-mancers/rapidfire/badges/gpa.svg)](https://codeclimate.com/github/code-mancers/rapidfire)
[![Build Status](https://travis-ci.org/code-mancers/rapidfire.png?branch=master)](https://travis-ci.org/code-mancers/rapidfire)

One stop solution for all survey related requirements! Its tad easy!

This gem supports **rails 3.2.13+**, **rails4** and **rails5** versions.

You can see a demo of this gem [here](https://rapidfire.herokuapp.com).
And the source code of demo [here](https://github.com/code-mancers/rapidfire-demo).

## Installation
Add this line to your application's Gemfile:

```rb
    gem 'rapidfire'
```

And then execute:

```shell
    $ bundle install
    $ bundle exec rake rapidfire:install:migrations
    $ bundle exec rake db:migrate
```

And if you want to customize rapidfire views, you can do

    $ bundle exec rails generate rapidfire:views

If you want to customize rapidfire locales (i18n) files, you can do

    $ bundle exec rails generate rapidfire:locales

## Usage

Add this line to your routes will and you will be good to go!

```rb
    mount Rapidfire::Engine => "/rapidfire"
```

And point your browser to [http://localhost:3000/rapidfire](http://localhost:3000/rapidfire)

All rapidfire controllers inherit from your `ApplicationController`. So define 2
methods `current_user` and `can_administer?` on your `ApplicationController`

1. `current_user` : the user who is answering the survey. can be `nil`
2. `can_administer?` : a method which determines whether current user can
   create/update survey questions.

Typical implementation would be:

```rb
  class ApplicationController < ActionController::Base
    def current_user
      @current_user ||= User.find(session[:user_id])
    end

    def can_administer?
      current_user.try(:admin?)
    end
  end
```

If you are using authentication gems like devise, you get `current_user` for free
and you don't have to define it.

### Override

Override path to redirect after answer the survey

```ruby
# my_app/app/decorators/controllers/rapidfire/answer_groups_controller_decorator.rb
Rapidfire::AnswerGroupsController.class_eval do
  def after_answer_path_for
    main_app.root_path
  end
end
```

### Routes Information
Once this gem is mounted on, say at 'rapidfire', it generates several routes
You can see them by running `bundle exec rake routes`.

1. The `root_path` i.e `localhost:3000/rapidfire` always points to list of
   surveys {they are called question groups}. Admin can manage surveys, and
   any user {who cannot administer} can see list of surveys.
2. Optionally, each survey can by answered by visiting this path:

   ```
     localhost:3000/rapidfire/surveys/<survey-id>/answer_groups/new
   ```

   You can distribute this url so that survey takers can answer a particular survey
   of your interest.

### Survey Results
A new api is released which helps in seeing results for each survey. The api is:

```
  GET /rapidfire/surveys/<survey-id>/results
```
This new api supports two formats: `html` and `json`. The `json` format is supported
so that end user can use any javascript based chart solutions and render results
in the format they pleased. An example can be seen [here](https://github.com/code-mancers/rapidfire-demo),
which uses chart.js to display results.
<commit_msg>Include info on how to prevent routing errors<commit_after># Rapidfire
[![Code Climate](https://codeclimate.com/github/code-mancers/rapidfire/badges/gpa.svg)](https://codeclimate.com/github/code-mancers/rapidfire)
[![Build Status](https://travis-ci.org/code-mancers/rapidfire.png?branch=master)](https://travis-ci.org/code-mancers/rapidfire)

One stop solution for all survey related requirements! Its tad easy!

This gem supports **rails 3.2.13+**, **rails4** and **rails5** versions.

You can see a demo of this gem [here](https://rapidfire.herokuapp.com).
And the source code of demo [here](https://github.com/code-mancers/rapidfire-demo).

## Installation
Add this line to your application's Gemfile:

```rb
    gem 'rapidfire'
```

And then execute:

```shell
    $ bundle install
    $ bundle exec rake rapidfire:install:migrations
    $ bundle exec rake db:migrate
```

And if you want to customize rapidfire views, you can do

    $ bundle exec rails generate rapidfire:views

If you want to customize rapidfire locales (i18n) files, you can do

    $ bundle exec rails generate rapidfire:locales

## Usage

Add this line to your routes will and you will be good to go!

```rb
    mount Rapidfire::Engine => "/rapidfire"
```

And point your browser to [http://localhost:3000/rapidfire](http://localhost:3000/rapidfire)

All rapidfire controllers inherit from your `ApplicationController`. So define 2
methods `current_user` and `can_administer?` on your `ApplicationController`

1. `current_user` : the user who is answering the survey. can be `nil`
2. `can_administer?` : a method which determines whether current user can
   create/update survey questions.

Typical implementation would be:

```rb
  class ApplicationController < ActionController::Base
    def current_user
      @current_user ||= User.find(session[:user_id])
    end

    def can_administer?
      current_user.try(:admin?)
    end
  end
```

If you are using authentication gems like devise, you get `current_user` for free
and you don't have to define it.

### Override

Override path to redirect after answer the survey

```ruby
# my_app/app/decorators/controllers/rapidfire/answer_groups_controller_decorator.rb
Rapidfire::AnswerGroupsController.class_eval do
  def after_answer_path_for
    main_app.root_path
  end
end
```

### Routes Information
Once this gem is mounted on, say at 'rapidfire', it generates several routes
You can see them by running `bundle exec rake routes`.

1. The `root_path` i.e `localhost:3000/rapidfire` always points to list of
   surveys {they are called question groups}. Admin can manage surveys, and
   any user {who cannot administer} can see list of surveys.
2. Optionally, each survey can by answered by visiting this path:

   ```
     localhost:3000/rapidfire/surveys/<survey-id>/answer_groups/new
   ```

   You can distribute this url so that survey takers can answer a particular survey
   of your interest.
3. 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:
   
   ```
   Rapidfire::ApplicationController.class_eval do
     helper Rails.application.routes.url_helpers
   end
   ```

### Survey Results
A new api is released which helps in seeing results for each survey. The api is:

```
  GET /rapidfire/surveys/<survey-id>/results
```
This new api supports two formats: `html` and `json`. The `json` format is supported
so that end user can use any javascript based chart solutions and render results
in the format they pleased. An example can be seen [here](https://github.com/code-mancers/rapidfire-demo),
which uses chart.js to display results.

{'fraction_non_alphanumeric': 0.09557174887892377, 'fraction_numerical': 0.008548206278026906, 'mean_word_length': 4.322147651006712, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6284279', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2077, 'n_words': 791}