Class: HelenaAdministration::VersionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/helena_administration/versions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_breadcrumb, #set_locale

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/helena_administration/versions_controller.rb', line 21

def create
  @version = build_version
  @version.update_attributes(version_params)
  if @version.save
    flash[:success] = t 'shared.actions.created'
  else
    flash.now[:danger] = t 'shared.actions.error'
  end
  respond_with @version, location: [@survey, @version]
end

#destroyObject



51
52
53
54
55
# File 'app/controllers/helena_administration/versions_controller.rb', line 51

def destroy
  @version = @survey.versions.find params[:id]
  flash[:success] = t 'shared.actions.deleted' if @version.destroy
  redirect_to survey_path(@survey)
end

#editObject



32
33
34
35
# File 'app/controllers/helena_administration/versions_controller.rb', line 32

def edit
  @version.survey_detail ||= Helena::SurveyDetail.new
  add_breadcrumb t 'helena_administration.versions.version', version: @version.version
end

#newObject



12
13
14
15
16
17
18
19
# File 'app/controllers/helena_administration/versions_controller.rb', line 12

def new
  source_version = @survey.newest_version
  @version = @survey.versions.any? ? @survey.versions.build(source_version.attributes) : @survey.versions.build
  @version.parent = source_version
  @version.survey_detail = (@version.try(:survey_detail) || Helena::SurveyDetail.new)
  @version.notes = ''
  add_breadcrumb t('.new'), new_survey_version_path(@survey)
end

#showObject



8
9
10
# File 'app/controllers/helena_administration/versions_controller.rb', line 8

def show
  add_breadcrumb t 'helena_administration.versions.version', version: @version.version
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/helena_administration/versions_controller.rb', line 37

def update
  @version.update_attributes version_params

  # Note: Not used at the moment, because there are no validations atm
  # if @version.update_attributes version_params
  #   flash[:success] = t 'shared.actions.updated'
  # else
  #   flash.now[:danger] = t 'shared.actions.error'
  #   add_breadcrumb t 'helena_administration.versions.version', version: @version.version
  # end
  flash[:success] = t 'shared.actions.updated'
  respond_with @version, location: [:edit, @survey, @version]
end