Class: Voluntary::Api::V1::Music::ArtistsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/voluntary/api/v1/music/artists_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/voluntary/api/v1/music/artists_controller.rb', line 8

def index
  params[:page] = nil if params[:page] == ''
  params[:per_page] = nil if params[:per_page] == ''
  artists = MusicArtist
  artists = artists.where(state: params[:state]) if params[:state].present?
  artists = artists.order('name ASC').paginate(per_page: params[:per_page] || 10, page: params[:page] || 1)
  
  respond_to do |format|
    format.json {
      render json: {
        current_page: artists.current_page, per_page: artists.per_page, total_entries: artists.total_entries, total_pages: artists.total_pages,
        entries: artists.map(&:to_json),
      }.to_json
    }
  end
end

#showObject



25
26
27
28
29
# File 'app/controllers/voluntary/api/v1/music/artists_controller.rb', line 25

def show
  respond_to do |format|
    format.json { render json: MusicArtist.find(params[:id]).to_json }
  end
end