Class: RailsAdminImageManager::ImagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RailsAdminImageManager::ImagesController
- Defined in:
- app/controllers/rails_admin_image_manager/images_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #tags ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 75 def create (:create) my_params = images_params # Handling dynamic tag creating when receiving a string = [] images_params[:tags].each do |tag_string| << RailsAdminImageManager::Tag.retrieve_or_create_tag(tag_string) end my_params[:tags] = image = RailsAdminImageManager::File.new(my_params) if image.save() render json: image, status: :ok else render json: image.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 95 def destroy (:destroy) image = RailsAdminImageManager::File.find(params[:id]) if image.destroy render json: image, status: :ok else render json: image.errors, status: :unprocessable_entity end end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 4 def index respond_to do |format| format.html { @tags = RailsAdminImageManager::Tag.with_files } format.json { images = RailsAdminImageManager::File.select(:id, :name, :image_file_name, :created_at).order(:name).page(params[:page]) images = images.filter_by_text(params[:search]) if filter_by?(:search) images = images.(params[:tags].map{|i| i.to_i }) if filter_by?(:tags) images = images.order_by_date(params[:date]) if filter_by?(:date) images = images.order_by_title(params[:title]) if filter_by?(:title) images.each do |image| image.src = image.image.url(:index) end data = { items: images, total_count: images.total_count, limit_value: images.limit_value, readonly: readonly? } render json: data, methods: [:src, :tags_list], status: :ok } end end |
#new ⇒ Object
37 38 39 40 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 37 def new (:create) render json: {msg: 'ok'}, status: :ok end |
#show ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 42 def show (:update) image = RailsAdminImageManager::File.select(:id, :name, :description, :copyright, :image_file_name).find_by!(id: params[:id]) image.src = image.image.url(:show) image.src_for_wysiwyg = {width: params[:width], height: params[:height]} if filter_by?(:width) && filter_by?(:height) data = { image: image, readonly: readonly? } render json: data, methods: [:src, :src_for_wysiwyg, :tags_list], status: :ok end |
#tags ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 28 def respond_to do |format| format.json { = RailsAdminImageManager::Tag.with_files render json: , status: :ok } end end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/rails_admin_image_manager/images_controller.rb', line 54 def update (:update) my_params = images_params image = RailsAdminImageManager::File.find(my_params[:id]) # Handling dynamic tag creating when receiving a string = [] images_params[:tags].each do |tag_string| << RailsAdminImageManager::Tag.retrieve_or_create_tag(tag_string) end my_params[:tags] = # Updating image object if image.present? && image.update_attributes(my_params) render json: image, status: :ok else render json: image.errors, status: :unprocessable_entity end end |