Class: Voluntary::Api::V1::SurveyInputOptionsController

Inherits:
ActionController::Base
  • Object
show all
Includes:
V1::BaseController
Defined in:
app/controllers/voluntary/api/v1/survey_input_options_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/voluntary/api/v1/survey_input_options_controller.rb', line 16

def create
  story = Product::Survey::Story.find params[:survey_input_option][:story_id]
  
  authorize! :update, story
  
  resource = story.pages.find(params[:survey_input_option].delete(:page_id)).tasks.find(params[:survey_input_option].delete(:task_id)).options.create params[:survey_input_option]
  
  respond_to do |format|
    format.json do
      render json: resource.persisted? ? resource : { errors: resource.errors.to_hash }
    end
  end
end

#destroyObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/voluntary/api/v1/survey_input_options_controller.rb', line 45

def destroy
  story = Product::Survey::Story.find(params[:story_id])
  
  authorize! :destroy, story
  
  resource = story.pages.find(params[:page_id]).tasks.find(params[:task_id]).options.find params[:id]
  resource.destroy
  
  respond_to do |format|
    format.json do
      render json: if resource.persisted?
        { error: I18n.t('activerecord.errors.models.survey_page.attributes.base.deletion_failed') }
      else
        {}
      end
    end
  end
end

#showObject



6
7
8
9
10
11
12
13
14
# File 'app/controllers/voluntary/api/v1/survey_input_options_controller.rb', line 6

def show
  resource = Product::Survey::Story.find(params[:story_id]).pages.find(params[:page_id]).tasks.find(params[:task_id]).options.find params[:id]
    
  respond_to do |format|
    format.json do
      render json: resource
    end
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/voluntary/api/v1/survey_input_options_controller.rb', line 30

def update
  story = Product::Survey::Story.find params[:survey_input_option].delete(:story_id)
  
  authorize! :update, story
  
  resource = story.pages.find(params[:survey_input_option].delete(:page_id)).tasks.find(params[:survey_input_option].delete(:task_id)).options.find(params[:id])
  resource.update_attributes params[:survey_input_option]

  respond_to do |format|
    format.json do
      render json: resource.valid? ? resource : { errors: resource.errors.to_hash }
    end
  end
end