Class: LibrariesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- LibrariesController
- Defined in:
- app/controllers/libraries_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /libraries POST /libraries.json.
-
#destroy ⇒ Object
DELETE /libraries/1 DELETE /libraries/1.json.
-
#edit ⇒ Object
GET /libraries/1/edit.
-
#index ⇒ Object
GET /libraries GET /libraries.json.
-
#new ⇒ Object
GET /libraries/new.
-
#show ⇒ Object
GET /libraries/1 GET /libraries/1.json.
-
#update ⇒ Object
PUT /libraries/1 PUT /libraries/1.json.
Instance Method Details
#create ⇒ Object
POST /libraries POST /libraries.json
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/libraries_controller.rb', line 73 def create @library = Library.new(library_params) respond_to do |format| if @library.save format.html { redirect_to @library, notice: t('controller.successfully_created', model: t('activerecord.models.library')) } format.json { render json: @library, status: :created } else format.html { render action: "new" } format.json { render json: @library.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /libraries/1 DELETE /libraries/1.json
111 112 113 114 115 116 117 118 |
# File 'app/controllers/libraries_controller.rb', line 111 def destroy @library.destroy respond_to do |format| format.html { redirect_to libraries_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /libraries/1/edit
67 68 69 |
# File 'app/controllers/libraries_controller.rb', line 67 def edit end |
#index ⇒ Object
GET /libraries GET /libraries.json
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/libraries_controller.rb', line 7 def index sort = {sort_by: 'position', order: 'asc'} case params[:sort_by] when 'name' sort[:sort_by] = 'name' end sort[:order] = 'desc' if params[:order] == 'desc' query = @query = params[:query].to_s.strip page = params[:page] || 1 @libraries = Library.search(include: [:shelves]) do fulltext query if query.present? paginate page: page.to_i, per_page: Library.default_per_page order_by sort[:sort_by], sort[:order] end.results respond_to do |format| format.html # index.html.erb format.json { render json: @libraries } end end |
#new ⇒ Object
GET /libraries/new
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/libraries_controller.rb', line 54 def new @library = Library.new @library.library_group = LibraryGroup.first @library.country = LibraryGroup.site_config.country respond_to do |format| format.html # new.html.erb format.json { render json: @library } end end |
#show ⇒ Object
GET /libraries/1 GET /libraries/1.json
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/libraries_controller.rb', line 32 def show if defined?(EnjuEvent) search = Sunspot.new_search(Event) library_id = @library.id search.build do with(:library_id).equal_to library_id order_by(:start_at, :desc) end page = params[:event_page] || 1 search.query.paginate(page.to_i, Event.default_per_page) @events = search.execute!.results end respond_to do |format| format.html # show.html.erb format.html.phone format.json { render json: @library } format.js end end |
#update ⇒ Object
PUT /libraries/1 PUT /libraries/1.json
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/libraries_controller.rb', line 90 def update if params[:move] move_position(@library, params[:move]) return end respond_to do |format| if @library.update(library_params) format.html { redirect_to @library, notice: t('controller.successfully_updated', model: t('activerecord.models.library')) } format.json { head :no_content } else @library.name = @library.name_was format.html { render action: "edit" } format.json { render json: @library.errors, status: :unprocessable_entity } end end end |