Sha256: 6556b25fa4795826470be06fbc3bdefafcd2a9af8b5f674ac029484585988b7f

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

class NdlBooksController < ApplicationController
  before_filter :authenticate_user!
  before_filter :check_librarian

  def index
    if params[:page].to_i == 0
      page = 1
    else
      page = params[:page]
    end
    @query = params[:query].to_s.strip
    books = NdlBook.search(params[:query], page)
    @books = Kaminari.paginate_array(
      books[:items], :total_count => books[:total_entries], :page => page
    ).page(page).per(10)

    respond_to do |format|
      format.html
    end
  end

  def create
    if params[:book]
      @manifestation = NdlBook.import_from_sru_response(params[:book][:nbn])
      respond_to do |format|
        if @manifestation.try(:save)
          flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
          format.html { redirect_to manifestation_items_url(@manifestation) }
        else
          flash[:notice] = t('enju_ndl.record_not_found')
          format.html { redirect_to ndl_books_url }
        end
      end
    end
  #rescue ActiveRecord::RecordInvalid => e
  #  respond_to do |format|
  #    flash[:notice] = e.message
  #    format.html { render :action => "index" }
  #  end
  end

  private
  def check_librarian
    unless current_user.try(:has_role?, 'Librarian')
      access_denied
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
enju_ndl-0.1.0.pre15 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre14 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre13 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre12 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre11 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre10 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre9 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre8 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre7 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre6 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre5 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre4 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre3 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre2 app/controllers/ndl_books_controller.rb
enju_ndl-0.1.0.pre app/controllers/ndl_books_controller.rb