Class: Infold::AppsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/infold/apps_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/infold/apps_controller.rb', line 11

def create
  project = Project.first
  @app = App.new
  @app.assign_attributes(post_params)
  @app.build_app_view_index
  @app.build_app_view_show
  @app.app_views.compact.each(&:reject_unchecked)
  if @app.save
    project.menu_items.create!(app: @app, seq: project.menu_items.size + 1, kind: :app)
    redirect_to edit_app_path(@app), flash: { info: t('infold.flash.created') }
  else
    Rails.logger.debug "エラー #{@app.errors.full_messages}"
    flash.now[:warning] = t('infold.flash.invalid')
    render status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
50
# File 'app/controllers/infold/apps_controller.rb', line 46

def destroy
  @app = App.find(params[:id])
  @app.destroy!
  redirect_to new_app_path, status: :see_other, flash: { info: t('infold.flash.destroyed') }
end

#editObject



28
29
30
31
# File 'app/controllers/infold/apps_controller.rb', line 28

def edit
  @app = App.find(params[:id])
  @app.build_views
end

#indexObject



3
4
# File 'app/controllers/infold/apps_controller.rb', line 3

def index
end

#newObject



6
7
8
9
# File 'app/controllers/infold/apps_controller.rb', line 6

def new
  @app = App.new
  @app.build_views
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/infold/apps_controller.rb', line 33

def update
  @app = App.find(params[:id])
  @app.assign_attributes(post_params)
  @app.app_views.compact.each(&:reject_unchecked)
  if @app.save
    redirect_to edit_app_path(@app), flash: { info: t('infold.flash.updated') }
  else
    Rails.logger.debug "エラー #{@app.errors.full_messages}"
    flash.now[:warning] = t('infold.flash.invalid')
    render status: :unprocessable_entity
  end
end