This commit is contained in:
San Wai Lwin
2018-03-13 14:46:07 +06:30
parent 9ec8c4d18c
commit 694feb9c06
9 changed files with 151 additions and 5 deletions

View File

@@ -0,0 +1,11 @@
class Settings::DisplayImagesController < ApplicationController
def destroy
#byebug
@item_photo = DisplayImage.find(params[:shop_id])
item = @item_photo.id
@item_photo.destroy
respond_to do |format|
format.html {redirect_to settings_shops_url+'/1/edit', notice: 'Image was successfully destroyed.'}
end
end
end

View File

@@ -1,6 +1,6 @@
class Settings::ShopsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_shop, only: [:show, :edit, :update]
before_action :set_shop, only: [:show, :edit, :update, :destroy]
# GET /settings/shops
# GET /settings/shops.json
@@ -11,11 +11,13 @@ class Settings::ShopsController < ApplicationController
# GET /settings/shops/1
# GET /settings/shops/1.json
def show
@display_images = @settings_shop.display_images.all
end
# GET /settings/shops/new
def new
@settings_shop = Shop.new
@display_image = @settings_shop.display_images.build
end
# GET /settings/shops/1/edit
@@ -28,6 +30,11 @@ class Settings::ShopsController < ApplicationController
@settings_shop = Shop.new(shop_params)
respond_to do |format|
if @settings_shop.save
if params[:display_images].present?
params[:display_images]['image'].each do |a|
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
end
end
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' }
format.json { render :index, status: :created, location: @settings_shop }
else
@@ -42,6 +49,11 @@ class Settings::ShopsController < ApplicationController
def update
respond_to do |format|
if @settings_shop.update(shop_params)
if params[:display_images].present?
params[:display_images]['image'].each do |a|
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
end
end
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' }
format.json { render :index, status: :ok, location: @settings_shop }
else
@@ -71,6 +83,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(: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)
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, display_images_attributes: [:id, :shop_id, :image])
end
end