From 0ad3ff01c3554bdf7ba0958cd77ad5224100328c Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Apr 2016 15:27:33 +0200 Subject: [PATCH] Use PictureUploader on Lodging --- app/controllers/admin/lodgings_controller.rb | 2 +- app/models/lodging.rb | 7 +------ app/views/admin/lodgings/_form.html.haml | 6 +++--- app/views/admin/lodgings/index.html.haml | 6 +++--- app/views/conference/_lodging.html.haml | 7 +++---- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin/lodgings_controller.rb b/app/controllers/admin/lodgings_controller.rb index 5e94d53a..e128dcd5 100644 --- a/app/controllers/admin/lodgings_controller.rb +++ b/app/controllers/admin/lodgings_controller.rb @@ -47,7 +47,7 @@ module Admin private def lodging_params - params.require(:lodging).permit(:name, :description, :photo, :website_link, :conference_id) + params.require(:lodging).permit(:name, :description, :picture, :picture_cache, :website_link, :conference_id) end end end diff --git a/app/models/lodging.rb b/app/models/lodging.rb index aa01505c..48031eba 100644 --- a/app/models/lodging.rb +++ b/app/models/lodging.rb @@ -3,10 +3,5 @@ class Lodging < ActiveRecord::Base validates :name, presence: true - has_attached_file :photo, - styles: { thumb: '100x100>', large: '300x300>' } - - validates_attachment_content_type :photo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :photo_file_name end diff --git a/app/views/admin/lodgings/_form.html.haml b/app/views/admin/lodgings/_form.html.haml index d34a1b8c..d5ab72e5 100644 --- a/app/views/admin/lodgings/_form.html.haml +++ b/app/views/admin/lodgings/_form.html.haml @@ -12,8 +12,8 @@ = f.input :name = f.input :website_link = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint - - unless @lodging.photo.blank? - = image_tag @lodging.photo(:thumb) - = f.input :photo + - if @lodging.picture? + = image_tag @lodging.picture.thumb.url + = f.input :picture %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/lodgings/index.html.haml b/app/views/admin/lodgings/index.html.haml index 0775b7b9..1f3a89fb 100644 --- a/app/views/admin/lodgings/index.html.haml +++ b/app/views/admin/lodgings/index.html.haml @@ -10,15 +10,15 @@ - slice.each do |lodging| .col-md-4 .thumbnail - - if lodging.photo.blank? + - if !lodging.picture? %p.text-center %i.fa.fa-home.fa-5x - else -if lodging.website_link.present? = link_to(lodging.website_link, class: 'thumbnail') do - = image_tag lodging.photo(:thumb), class: 'img-responsive img-lodging' + = image_tag lodging.picture.thumb, class: 'img-responsive img-lodging' - else - = image_tag lodging.photo(:thumb), class: 'img-responsive img-lodging' + = image_tag lodging.picture.thumb, class: 'img-responsive img-lodging' .caption %h3.text-center = lodging.name diff --git a/app/views/conference/_lodging.html.haml b/app/views/conference/_lodging.html.haml index 7d603a68..ca30edc0 100644 --- a/app/views/conference/_lodging.html.haml +++ b/app/views/conference/_lodging.html.haml @@ -13,18 +13,17 @@ - slice.each do |lodging| .col-md-4.col-sm-4.ticket.col-centered.col-top .thumbnail - - if lodging.photo.blank? + - if !lodging.picture? %p.text-center %i.fa.fa-home.fa-5x - else -if lodging.website_link.present? = link_to(lodging.website_link, class: 'thumbnail') do - = image_tag lodging.photo(:large), class: 'img-responsive img-lodging' + = image_tag lodging.picture.large.url, class: 'img-responsive img-lodging' - else - = image_tag lodging.photo(:large), class: 'img-responsive img-lodging' + = image_tag lodging.picture.large.url, class: 'img-responsive img-lodging' .caption %h3.text-center = lodging.name -if lodging.description.present? = markdown(lodging.description) -