Module: Ez::Resources::Manager
- Includes:
- Cell::RailsExtensions::ActionController
- Defined in:
- lib/ez/resources/manager.rb,
lib/ez/resources/manager/dsl.rb,
lib/ez/resources/manager/hook.rb,
lib/ez/resources/manager/field.rb,
lib/ez/resources/manager/hooks.rb,
lib/ez/resources/manager/action.rb,
lib/ez/resources/manager/config.rb,
lib/ez/resources/manager/fields.rb,
lib/ez/resources/manager/config_store.rb
Defined Under Namespace
Modules: DSL
Classes: Action, Config, ConfigStore, Field, Fields, Hook, Hooks
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/ez/resources/manager.rb', line 11
def self.included(base)
base.extend(DSL)
base.rescue_from UnavailableError do
if Ez::Resources.config.ui_failed_hook
instance_exec(&Ez::Resources.config.ui_failed_hook)
else
flash[:alert] = t('messages.unavailable', scope: Ez::Resources.config.i18n_scope)
redirect_to '/'
end
end
end
|
Instance Method Details
#create ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ez/resources/manager.rb', line 46
def create
Manager::Hooks.can!(:can_create?, ez_resource_config)
@ez_resource = ez_resource_config.model.new(ez_resource_params)
if @ez_resource.save
flash[:notice] = t('messages.created',
resource_name: ez_resource_config.resource_name,
scope: Ez::Resources.config.i18n_scope)
redirect_to ez_resource_config.path_for(action: :index)
else
flash[:alert] = t('messages.invalid',
resource_name: ez_resource_config.resource_name,
scope: Ez::Resources.config.i18n_scope)
ez_resource_view :form, ez_resource_config
end
end
|
#destroy ⇒ Object
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/ez/resources/manager.rb', line 92
def destroy
Manager::Hooks.can?(:can_destroy?, ez_resource_config, ez_resource_config.data)
ez_resource_config.data.delete
flash[:notice] = t('messages.removed',
resource_name: ez_resource_config.resource_name,
scope: Ez::Resources.config.i18n_scope)
redirect_to ez_resource_config.path_for(action: :index)
end
|
#edit ⇒ Object
66
67
68
69
70
|
# File 'lib/ez/resources/manager.rb', line 66
def edit
Manager::Hooks.can!(:can_update?, ez_resource_config, ez_resource_config.data)
ez_resource_view :form, ez_resource_config
end
|
#index ⇒ Object
24
25
26
27
28
|
# File 'lib/ez/resources/manager.rb', line 24
def index
Manager::Hooks.can!(:can_list?, ez_resource_config)
ez_resource_view :collection, ez_resource_config
end
|
#new ⇒ Object
40
41
42
43
44
|
# File 'lib/ez/resources/manager.rb', line 40
def new
Manager::Hooks.can!(:can_create?, ez_resource_config)
ez_resource_view :form, ez_resource_config
end
|
#show ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/ez/resources/manager.rb', line 30
def show
Manager::Hooks.can!(:can_read?, ez_resource_config)
if ez_resource_config.show_action_renders_form?
ez_resource_view :form, ez_resource_config
else
end
end
|
#update ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/ez/resources/manager.rb', line 72
def update
Manager::Hooks.can!(:can_update?, ez_resource_config, ez_resource_config.data)
@ez_resource = ez_resource_config.data
if @ez_resource.update(ez_resource_params)
flash[:notice] = t('messages.updated',
resource_name: ez_resource_config.resource_name,
scope: Ez::Resources.config.i18n_scope)
redirect_to ez_resource_config.path_for(action: :index)
else
flash[:alert] = t('messages.invalid',
resource_name: ez_resource_config.resource_name,
scope: Ez::Resources.config.i18n_scope)
ez_resource_view :form, ez_resource_config
end
end
|