Module: MegaScaffold::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/mega_scaffold/controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
# File 'lib/mega_scaffold/controller.rb', line 33

def create
  @record = collection.build(record_params)
  if @record.save
    flash[:notice] = "#{mega_scaffold.model} successfully created"
    redirect_to url_for({ action: :show, mega_scaffold.pk => @record.send(mega_scaffold.pk) })
  else
    render template: 'mega_scaffold/new', status: :unprocessable_entity
  end
end

#destroyObject



58
59
60
61
62
63
# File 'lib/mega_scaffold/controller.rb', line 58

def destroy
  @record = resource
  @record.destroy
  flash[:notice] = "#{mega_scaffold.model} successfully deleted"
  redirect_to action: :index
end

#editObject



43
44
45
46
# File 'lib/mega_scaffold/controller.rb', line 43

def edit
  @record = resource
  render template: 'mega_scaffold/edit'
end

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/mega_scaffold/controller.rb', line 12

def index
  @records = if defined?(Kaminari)
    collection.page(params[:page])
  elsif defined?(WillPaginate)
    collection.paginate(params[:page])
  else
    collection
  end
  render template: 'mega_scaffold/index'
end

#newObject



28
29
30
31
# File 'lib/mega_scaffold/controller.rb', line 28

def new
  @record = collection.new
  render template: 'mega_scaffold/new'
end

#showObject



23
24
25
26
# File 'lib/mega_scaffold/controller.rb', line 23

def show
  @record = resource
  render template: 'mega_scaffold/show'
end

#updateObject



48
49
50
51
52
53
54
55
56
# File 'lib/mega_scaffold/controller.rb', line 48

def update
  @record = resource
  if @record.update(record_params)
    flash[:notice] = "#{mega_scaffold.model} successfully updated"
    redirect_to url_for({ action: :show, mega_scaffold.pk => @record.send(mega_scaffold.pk) })
  else
    render template: 'mega_scaffold/edit', status: :unprocessable_entity
  end
end