Module: QuestionChain::Answers::InstanceMethods

Defined in:
lib/question_chain/answers.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
  enforce_permission
  @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] = create_success_flash_message
      @contexts << @answer
      redirect_to create_success_path
    end      
  end
end

#editObject



20
21
22
23
24
25
26
27
# File 'lib/question_chain/answers.rb', line 20

def edit
  @answer = resource
  enforce_permission
  @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_permissionObject



104
105
106
# File 'lib/question_chain/answers.rb', line 104

def enforce_permission
  # override to force permission on the answer object
end

#fire_object_searchObject

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.get_options(params[:q], params[:relatable_category_values])}.to_json
    end
  end
  render :json => {:error => "Could not find rule"}.to_json
end

#fire_populate_drop_downObject

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.get_options(params[:object_ids])}.to_json
    end
  end
  render :json => {:error => "Could not find rule"}.to_json
end

#indexObject

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

#newObject



13
14
15
16
17
18
# File 'lib/question_chain/answers.rb', line 13

def new
  @answer = build_resource
  enforce_permission
  @question = question_from_context
  new!
end

#showObject

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

#updateObject



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
  enforce_permission
  @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] = update_success_flash_message
      @contexts << @answer
      redirect_to update_success_path
    end
  end
end