Class: Arturo::FeaturesController

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

Overview

Handles all Feature actions. Clients of the Arturo engine should redefine Arturo::FeaturesController#permitted? 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



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

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

#destroyObject



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

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 features_path
end

#editObject



66
67
68
# File 'app/controllers/arturo/features_controller.rb', line 66

def edit
  respond_with @feature
end

#indexObject



19
20
21
22
# File 'app/controllers/arturo/features_controller.rb', line 19

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

#newObject



50
51
52
53
# File 'app/controllers/arturo/features_controller.rb', line 50

def new
  @feature = Arturo::Feature.new(params[:feature])
  respond_with @feature
end

#showObject



46
47
48
# File 'app/controllers/arturo/features_controller.rb', line 46

def show
  respond_with @feature
end

#updateObject



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

def update
  if @feature.update_attributes(params[:feature])
    flash[:notice] = t('arturo.features.flash.updated', :name => @feature.to_s)
    redirect_to feature_path(@feature)
  else
      flash[:alert] = t('arturo.features.flash.error_updating', :name => @feature.to_s)
    render :action => 'edit'
  end
end

#update_allObject



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

def update_all
  updated_count = 0
  errors = []
  features_params = params[:features] || {}
  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)
    end
  end
  if errors.any?
    flash[:error] = errors
  else
    flash[:success] = t('arturo.features.flash.updated_many', :count => updated_count)
  end
  redirect_to features_path
end