Class: Arturo::FeaturesController

Inherits:
ApplicationController
  • Object
show all
Includes:
FeatureManagement, FeatureParamsSupport
Defined in:
app/controllers/arturo/features_controller.rb

Overview

Handles all Feature actions. Clients of the Arturo engine should redefine Arturo::FeaturesController#may_manage_features? to return true only for users who are permitted to manage features.

Instance Method Summary collapse

Methods included from FeatureManagement

#may_manage_features?

Instance Method Details

#createObject



57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/arturo/features_controller.rb', line 57

def create
  @feature = Arturo::Feature.new(feature_params)
  if @feature.save
    flash[:notice] = t('arturo.features.flash.created', :name => @feature.to_s)
    redirect_to arturo_engine.features_path
  else
    flash[:alert] = t('arturo.features.flash.error_creating', :name => @feature.to_s)
    render :action => 'new'
  end
end

#destroyObject



82
83
84
85
86
87
88
89
# File 'app/controllers/arturo/features_controller.rb', line 82

def destroy
  if @feature.destroy
    flash[:notice] = t('arturo.features.flash.removed', :name => @feature.to_s)
  else
    flash[:alert] = t('arturo.features.flash.error_removing', :name => @feature.to_s)
  end
  redirect_to arturo_engine.features_path
end

#editObject



68
69
70
# File 'app/controllers/arturo/features_controller.rb', line 68

def edit
  respond_with @feature
end

#indexObject



22
23
24
25
# File 'app/controllers/arturo/features_controller.rb', line 22

def index
  @features = Arturo::Feature.all
  respond_with @features
end

#newObject



52
53
54
55
# File 'app/controllers/arturo/features_controller.rb', line 52

def new
  @feature = Arturo::Feature.new(feature_params)
  respond_with @feature
end

#showObject



48
49
50
# File 'app/controllers/arturo/features_controller.rb', line 48

def show
  respond_with @feature
end

#updateObject



72
73
74
75
76
77
78
79
80
# File 'app/controllers/arturo/features_controller.rb', line 72

def update
  if @feature.update(feature_params)
    flash[:notice] = t('arturo.features.flash.updated', :name => @feature.to_s)
    redirect_to arturo_engine.feature_path(@feature)
  else
    flash[:alert] = t('arturo.features.flash.error_updating', :name => @feature.name, :errors => @feature.errors.full_messages.join("\n"))
    render :action => 'edit'
  end
end

#update_allObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/arturo/features_controller.rb', line 27

def update_all
  updated_count = 0
  errors = []
  features_params.each do |id, attributes|
    feature = Arturo::Feature.find_by_id(id)
    if feature.blank?
      errors << t('arturo.features.flash.no_such_feature', :id => id)
    elsif feature.update(attributes)
      updated_count += 1
    else
      errors << t('arturo.features.flash.error_updating', :id => id, :errors => feature.errors.full_messages.to_sentence)
    end
  end
  if errors.any?
    flash[:error] = errors
  else
    flash[:success] = t('arturo.features.flash.updated_many', :count => updated_count)
  end
  redirect_to arturo_engine.features_path
end