From 9f29bbef5a03360ed5fb1cb7890445813a27ca3b Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 7 Mar 2018 12:41:49 +0630 Subject: [PATCH] To add image field in shop --- app/controllers/settings/shops_controller.rb | 2 +- app/models/shop.rb | 3 + app/uploaders/shop_image_uploader.rb | 59 ++++++++ app/views/settings/products/_form.html.erb | 2 +- app/views/settings/shops/_form.html.erb | 144 +++++++++++-------- app/views/settings/shops/show.html.erb | 6 +- 6 files changed, 149 insertions(+), 67 deletions(-) create mode 100644 app/uploaders/shop_image_uploader.rb diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index a48bcb9a..f69aaac6 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -71,6 +71,6 @@ class Settings::ShopsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def shop_params - params.require(:shop).permit(:name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info) + params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info) end end diff --git a/app/models/shop.rb b/app/models/shop.rb index c722adc2..0fd9ed0e 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -1,3 +1,6 @@ class Shop < ApplicationRecord ShopDetail = Shop.find_by_id(1) + + # Shop Image Uploader + mount_uploader :logo, ShopImageUploader end diff --git a/app/uploaders/shop_image_uploader.rb b/app/uploaders/shop_image_uploader.rb new file mode 100644 index 00000000..63a01c21 --- /dev/null +++ b/app/uploaders/shop_image_uploader.rb @@ -0,0 +1,59 @@ +class ShopImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + def root + Rails.root.join 'public/' + end + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "image/shop_images" + # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # def cache_dir + # '/tmp/images' + # end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + process :resize_to_fit => [200, 150] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_whitelist + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end \ No newline at end of file diff --git a/app/views/settings/products/_form.html.erb b/app/views/settings/products/_form.html.erb index f9ad882b..bea0f004 100755 --- a/app/views/settings/products/_form.html.erb +++ b/app/views/settings/products/_form.html.erb @@ -12,7 +12,7 @@ <%= f.input :unit_price %> <%= f.input :description %> <%= f.input :information %> - <%= f.input:taxable %> + <%= f.input :taxable %> diff --git a/app/views/settings/shops/_form.html.erb b/app/views/settings/shops/_form.html.erb index 5a353b9b..b615d189 100755 --- a/app/views/settings/shops/_form.html.erb +++ b/app/views/settings/shops/_form.html.erb @@ -1,68 +1,86 @@
- <%= simple_form_for([:settings,@settings_shop]) do |f| %> - <%= f.error_notification %> -
- <%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%> - - <%= f.input :address %> - <%= f.input :city %> - <%= f.input :township %> - <%= f.input :state %> - <%= f.input :phone_no %> - <%= f.input :reservation_no %> - <%= f.input :license %> - <%= f.input :license_data %> - <%= f.input :base_currency %> - <%= f.input :cloud_token %> - <%= f.input :cloud_url %> - <%= f.input :owner_token %> - <%= f.input :id_prefix %> - <%= f.input :is_rounding_adj %> - <%= f.input :quick_sale_summary %> - <%= f.input :calc_tax_order %> - <%= f.input :show_account_info %> +
+
+ <%= simple_form_for([:settings,@settings_shop]) do |f| %> + <%= f.error_notification %> +
+ <%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%> + <%= f.input :address %> + <%= f.input :city %> + <%= f.input :township %> + <%= f.input :state %> + <%= f.input :phone_no %> + <%= f.input :reservation_no %> + <%= f.input :license %> + <%= f.input :license_data %> + <%= f.input :base_currency %> + <%= f.input :cloud_token %> + <%= f.input :cloud_url %> + <%= f.input :owner_token %> + <%= f.input :id_prefix %> + <%= f.input :is_rounding_adj %> + <%= f.input :quick_sale_summary %> + <%= f.input :calc_tax_order %> + <%= f.input :show_account_info %> +
- -
-
- <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> -
- <% end %> -
-
-
-
-
view_headline <%= t("views.right_panel.header.page_detail") %>
-

- 1) address - to write shop's address
- 2) city - to write city
- 3) township - to write township
- 4) state - to write state
- 5) phone_no - to write shop's phone_no
- 6) reservation_no - to write shop's reservation_no
- 7) license - to write license
- 8) license_data - to write license data
- 9) base_currency - to write base currency
- 10)cloud_token - to write cloud token
- 11)cloud_url - to write cloud url
- 12)owner_token - to write shop's owner token
- 13)id_prefix - to write id prefix
- 14)is_rounding_adj - to check for calculate rounding adj of shop
- 15)quick_sale_summary - to check for view Quick Sale Summary
- 16)calc_tax_order - to check for tax calculation of shop
- -

-
list <%= t("views.right_panel.header.button_lists") %>
-

- 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
-

-
list <%= t("views.right_panel.header.link_lists") %>
-

- 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
- 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
-

+ +
+
+ + <%= f.file_field :logo, :class => "img-thumbnail" %> +
+
+ +
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
-
-
+
+ +
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) address - to write shop's address
+ 2) city - to write city
+ 3) township - to write township
+ 4) state - to write state
+ 5) phone_no - to write shop's phone_no
+ 6) reservation_no - to write shop's reservation_no
+ 7) license - to write license
+ 8) license_data - to write license data
+ 9) base_currency - to write base currency
+ 10)cloud_token - to write cloud token
+ 11)cloud_url - to write cloud url
+ 12)owner_token - to write shop's owner token
+ 13)id_prefix - to write id prefix
+ 14)is_rounding_adj - to check for calculate rounding adj of shop
+ 15)quick_sale_summary - to check for view Quick Sale Summary
+ 16)calc_tax_order - to check for tax calculation of shop
+ +

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.shop_txt") %>
+

+
+
+
diff --git a/app/views/settings/shops/show.html.erb b/app/views/settings/shops/show.html.erb index 8fd9c5f0..bea0ab38 100755 --- a/app/views/settings/shops/show.html.erb +++ b/app/views/settings/shops/show.html.erb @@ -96,8 +96,10 @@ <%= @settings_shop.calc_tax_order %> - - + Shop Image + <%= image_tag @settings_shop.logo, :size => '200x200'%> + + <%= link_to t("views.btn.edit"), edit_settings_shop_path(@settings_shop),:class => 'btn btn-primary btn-sm waves-effect' %>