Class: Tramway::Admin::SingletonsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tramway/admin/singletons_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#application, #check_available!, #check_available_scope!, #collections_counts, #decorator_class, #form_class, #model_class

Methods included from RecordRoutesHelper

#edit_record_path, #new_record_path, #record_path, #records_path

Instance Method Details

#create ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/controllers/tramway/admin/singletons_controller.rb', line 17

def create
  @singleton_form = form_class.new model_class.new
  if @singleton_form.submit params[:singleton]
    redirect_to params[:redirect] || singleton_path(model: params[:model])
  else
    render :edit
  end
end

#edit ⇒ Object



13
14
15
# File 'app/controllers/tramway/admin/singletons_controller.rb', line 13

def edit
  @singleton_form = form_class.new model_class.active.first
end

#show ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/controllers/tramway/admin/singletons_controller.rb', line 3

def show
  if model_class.active.first.present?
    @singleton = decorator_class.decorate model_class.active.first
  else
    @singleton_form = form_class.new model_class.new
    render :new
    return
  end
end

#update ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/controllers/tramway/admin/singletons_controller.rb', line 26

def update
  @singleton_form = form_class.new model_class.active.first
  if @singleton_form.submit params[:singleton]
    redirect_to params[:redirect] || singleton_path(model: params[:model])
  else
    render :edit
  end
end