Class: Selectors

Inherits:
Items
  • Object
show all
Defined in:
app/controllers/selectors.rb

Instance Method Summary collapse

Instance Method Details

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/selectors.rb', line 6

def show
  partials do
    show :search
    show :tags
  end

  respond_to do |f|
    if @model
      require_permission :view, @model

      @page, @per_page = (params.page || 1).to_i, Models::Item::PER_PAGE

      query = Models::Item.where(
        viewers: {_in: rad.user.major_roles},
        dependent: {_exists: false}
      ).sort([:created_at, -1]).paginate(@page, @per_page)

      tags = (@model.query + selected_tags).uniq
      query = query.where tags: {_all: tags} unless tags.empty?

      @model.items = query.all

      f.html{@html_title = @model.name}
      f.json{render json: @model}
    else
      f.html{render :not_found}
      f.json{render :not_found}
    end
  end
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/selectors.rb', line 37

def update
  require_permission :update, @model

  respond_to do |f|
    if @model.set(params.model).save
      flash.info = t :selector_updated

      f.js{reload_page}
      f.json{render :ok}
    else
      f.js{render action: :edit}
      f.json{render json: {errors: @model.errors}, status: :failed}
    end
  end
end