Skip to content

Conversation

@n1vedhar1
Copy link
Contributor

@n1vedhar1 n1vedhar1 commented Dec 22, 2024

#Add support for custom questions

#Approach

  • Added custom_question_types accessor so that new questions can be added via initializer

#Usage

  • Create a custom question model extending the existing type in app/models/rapidfire/question
    Eg:
    If we want to create a 'custom' question which behaves like short question
# app/models/rapidfire/questions/custom.rb
module Rapidfire
  module Questions
    class Custom < Rapidfire::Questions::Short
    end
  end
end

  • Create a partial for that in app/views/rapidfire/answers
#app/views/rapidfire/answers/_custom.html.erb
<%= render partial: "rapidfire/answers/errors", locals: {answer: answer} %>
<div class="form-group">
  <%= f.label :answer_text, answer.question.question_text.html_safe %>
  <%= f.text_field :answer_text, value: answer.answer_text || answer.question.default_text, placeholder: answer.question.placeholder %>
</div>

  • Add the created type in initializer file. (Create rapidfire.rb in app/config/initializers if not there)
# config/initializers/rapidfire.rb
Rapidfire.config do |config|
  config.custom_question_types = ["Rapidfire::Questions::Custom"]
end

#Screenshot
Screenshot 2024-12-22 at 6 11 18 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant