Sha256: a72ab3340b19d59f639dcc70457d5cb1213bc876ccd32157d44754032c2d9192

Contents?: true

Size: 1.25 KB

Versions: 13

Compression:

Stored size: 1.25 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 = WillPaginate::Collection.create(page, NdlBook.per_page, books[:total_entries]) do |pager|
      pager.replace books[:items]
    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

13 entries across 13 versions & 1 rubygems

Version Path
enju_ndl-0.0.35 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.34 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.33 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.32 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.31 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.30 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.29 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.27 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.26 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.25 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.24 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.23 app/controllers/ndl_books_controller.rb
enju_ndl-0.0.22 app/controllers/ndl_books_controller.rb