Class: AnimalsController

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

Constant Summary

Constants inherited from ApplicationController

ApplicationController::APP_DOMAIN

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #canonical_url, #check_domain, #ensure_domain, #get_notice

Instance Method Details

#indexObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/animals_controller.rb', line 4

def index
  canonical_url('/animals')
  
  @animals = Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter).
                    where(public: 1).
                    paginate(page: params[:page], per_page: 10).
                    order(updated_at: :desc).to_a.shuffle!
  
  # only show animals from orgs that have contact info
  @animals.select! {|animal| animal.organization.has_info? }
  respond_with(@animals)
end

#not_availableObject


31
32
33
34
35
36
37
38
# File 'app/controllers/animals_controller.rb', line 31

def not_available
  canonical_url('/animals/not_available')
  @animals = Animal.where(public: 1).
                    limit(5).
                    order(updated_at: :desc)
  
  respond_with(@animals)
end

#showObject


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/animals_controller.rb', line 17

def show
  canonical_url("/animals/#{params[:id]}")
  @animal = Rails.cache.fetch("public_animal_#{params[:id]}", expires_in: 15.minutes) do
    Animal.includes(:animal_color, :animal_sex, :species, :status, :organization, :spay_neuter).find(params[:id])
  end

  if @animal.public == 1
    impressionist(@animal, nil, unique: [:session_hash])
    respond_with(@animal)
  else
    redirect_to '/animals/not_available', status: 302
  end
end