Class: Effective::ClassifiedsController

Inherits:
ApplicationController
  • Object
show all
Includes:
CrudController
Defined in:
app/controllers/effective/classifieds_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/effective/classifieds_controller.rb', line 5

def index
  EffectiveResources.authorize!(self, :index, ::Effective::Classified)

  @page_title ||= view_context.classifieds_name_label

  @classifieds = ::Effective::Classified.classifieds(user: current_user).sorted
end

#showObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/effective/classifieds_controller.rb', line 13

def show
  @classified = resource_scope.find(params[:id])

  if @classified.respond_to?(:roles_permit?)
    raise Effective::AccessDenied.new('Access Denied', :show, @classified) unless @classified.roles_permit?(current_user)
  end

  EffectiveResources.authorize!(self, :show, @classified)

  if EffectiveResources.authorized?(self, :admin, :effective_classifieds)
    flash.now[:warning] = [
      'Hi Admin!',
      ('You are viewing a hidden posting.' unless @classified.published?),
      ("<a href='#{effective_classifieds.edit_admin_classified_path(@classified)}' class='alert-link'>Click here to edit settings</a>.")
    ].compact.join(' ')
  end

  @page_title ||= @classified.to_s

  respond_to do |format|
    format.html { }

    format.json {
      url = effective_classifieds.classified_url(@classified, format: :json)
      render(json: @classified.for_json.merge(url: url).to_json)
    }
  end

end