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

#arturo_engineObject



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

def arturo_engine
  self
end

#createObject



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/arturo/features_controller.rb', line 63

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



88
89
90
91
92
93
94
95
# File 'app/controllers/arturo/features_controller.rb', line 88

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



74
75
76
# File 'app/controllers/arturo/features_controller.rb', line 74

def edit
  respond_with @feature
end

#indexObject



28
29
30
31
# File 'app/controllers/arturo/features_controller.rb', line 28

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

#newObject



58
59
60
61
# File 'app/controllers/arturo/features_controller.rb', line 58

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

#showObject



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

def show
  respond_with @feature
end

#updateObject



78
79
80
81
82
83
84
85
86
# File 'app/controllers/arturo/features_controller.rb', line 78

def update
  if @feature.update_attributes(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.to_s)
    render :action => 'edit'
  end
end

#update_allObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/arturo/features_controller.rb', line 33

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(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