Module: QuestionChain::Answers::InstanceMethods
- Defined in:
- lib/question_chain/answers.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #enforce_permission ⇒ Object
-
#fire_object_search ⇒ Object
Rule firing for search.
-
#fire_populate_drop_down ⇒ Object
Rule firing for drop down.
-
#index ⇒ Object
seems strange but its true allows for pagination link to work when creating a new answer.
- #new ⇒ Object
-
#show ⇒ Object
seems strange but its true allows for pagination link to work inside list view when editing.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/question_chain/answers.rb', line 48 def create @answer = build_resource @answer.user_id = current_user.id @answer.answer_params = params[:answer] @answer_params = params[:answer] # used for mustache templates @question = question_from_context @answer.question_id = @question.id @answer.result = get_answer(@question, @answer_params) set_answer_values_on_question!(@question, @answer_params) build_answer_errors! create! do |success, failure| success.html do flash[:notice] = @contexts << @answer redirect_to create_success_path end end end |
#edit ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/question_chain/answers.rb', line 20 def edit @answer = resource @question = Question.find!(resource.question_id).to_hash @answer_params = @answer.answer_params # used for mustache templates set_answer_values_on_question!(@question, @answer_params) edit! end |
#enforce_permission ⇒ Object
104 105 106 |
# File 'lib/question_chain/answers.rb', line 104 def # override to force permission on the answer object end |
#fire_object_search ⇒ Object
Rule firing for search
79 80 81 82 83 84 85 86 |
# File 'lib/question_chain/answers.rb', line 79 def fire_object_search if ui_object = UiObject.find(params[:ui_object_id]) if rule = ui_object.rules.find(params[:rule_id]) return render :json => {"options" => rule.(params[:q], params[:relatable_category_values])}.to_json end end render :json => {:error => "Could not find rule"}.to_json end |
#fire_populate_drop_down ⇒ Object
Rule firing for drop down
69 70 71 72 73 74 75 76 |
# File 'lib/question_chain/answers.rb', line 69 def fire_populate_drop_down if ui_object = UiObject.find(params[:ui_object_id]) if rule = ui_object.rules.find(params[:rule_id]) return render :json => {"options" => rule.(params[:object_ids])}.to_json end end render :json => {:error => "Could not find rule"}.to_json end |
#index ⇒ Object
seems strange but its true allows for pagination link to work when creating a new answer
99 100 101 102 |
# File 'lib/question_chain/answers.rb', line 99 def index end_of_association_chain redirect_to new_from_context_path end |
#new ⇒ Object
13 14 15 16 17 18 |
# File 'lib/question_chain/answers.rb', line 13 def new @answer = build_resource @question = question_from_context new! end |
#show ⇒ Object
seems strange but its true allows for pagination link to work inside list view when editing
91 92 93 94 |
# File 'lib/question_chain/answers.rb', line 91 def show end_of_association_chain redirect_to edit_from_context_path end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/question_chain/answers.rb', line 29 def update @answer = resource @answer.user_id = current_user.id @answer.answer_params = params[:answer] @answer_params = params[:answer] # used for mustache templates @question = Question.find!(resource.question_id).to_hash @answer.result = get_answer(@question, @answer_params) set_answer_values_on_question!(@question, @answer_params) build_answer_errors! update! do |success, failure| success.html do flash[:notice] = @contexts << @answer redirect_to update_success_path end end end |