Class: Portfolio::Admin::SiteItemsController

Inherits:
Portfolio::ApplicationController show all
Defined in:
app/controllers/portfolio/admin/site_items_controller.rb

Direct Known Subclasses

SiteProjectsController

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 21

def create
  @item = resource.new(item_project_params.merge(site_id: params[:site_id]))

  if @item.save
    redirect_to [:edit, :admin, @site, @item], notice: 'Item project was successfully created.'
  else
    render :new
  end
end

#destroyObject



53
54
55
56
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 53

def destroy
  @item.destroy
  redirect_to [:admin, @site, @resource_name_p], notice: 'Item project was successfully destroyed.'
end

#editObject



17
18
19
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 17

def edit
  @image = SiteItemImage.new site_item: @item
end

#indexObject



9
10
11
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 9

def index
  @items = resource.where(site: @site)
end

#newObject



13
14
15
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 13

def new
  @item = resource.new site: @site
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/portfolio/admin/site_items_controller.rb', line 31

def update
  resp = @item.update(item_project_params)

  respond_to do |format|
    format.html {
      if resp
        redirect_to [:edit, :admin, @site, @item], notice: 'Item project was successfully updated.'
      else
        render :edit
      end
    }

    format.json {
      if resp
        render json: @item
      else
        render json: { errors: @item.errors.full_messages }, status: 400
      end
    }
  end
end