add CarrierWave gems for menu image upload

This commit is contained in:
Yan
2017-08-14 18:53:39 +06:30
parent ac47d7d8f0
commit f018a56027
8 changed files with 50 additions and 23 deletions

View File

@@ -36,6 +36,9 @@ gem 'tether-rails'
gem "font-awesome-rails"
gem 'rack-cors'
# image upload
gem 'carrierwave', '~> 1.0'
#Report and Printing gems
gem 'cups', '~> 0.0.7'
gem 'prawn'

View File

@@ -51,6 +51,10 @@ GEM
builder (3.2.3)
byebug (9.0.6)
cancancan (1.17.0)
carrierwave (1.1.0)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
chronic (0.10.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
@@ -250,6 +254,7 @@ DEPENDENCIES
bootstrap-datepicker-rails
byebug
cancancan (~> 1.10)
carrierwave (~> 1.0)
coffee-rails (~> 4.2)
cups (~> 0.0.7)
database_cleaner

View File

@@ -16,7 +16,7 @@ class Settings::SimpleMenuItemsController < ApplicationController
# GET /settings/menu_items/new
def new
@settings_menu_item = MenuItem.new
@settings_menu_item = MenuItem.new
end
# GET /settings/menu_items/1/edit
@@ -27,6 +27,7 @@ class Settings::SimpleMenuItemsController < ApplicationController
# POST /settings/menu_items.json
def create
@settings_menu_item = MenuItem.new(settings_menu_item_params)
# @settings_menu_item.image_path = params[:image_path]
if params[:simple_menu_item][:menu_item_id] == ''
@settings_menu_item.menu_category_id = params[:menu_category_id]
end
@@ -78,6 +79,6 @@ class Settings::SimpleMenuItemsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def settings_menu_item_params
params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id,:account_id,:item_attributes, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by)
params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id,:account_id,:item_attributes, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by)
end
end

View File

@@ -15,6 +15,9 @@ class MenuItem < ApplicationRecord
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
# Item Image Uploader
mount_uploader :image_path, MenuItemImageUploader
def self.collection
MenuItem.select("id, name").map { |e| [e.name, e.id] }
end

View File

@@ -1,17 +1,24 @@
<%= simple_form_for([:settings,@category, @settings_menu_item]) do |f| %>
<%= f.error_notification %>
<div class="col-md-4">
<div class="menu-item-img">
<%= f.file_field :image_path, :class => "img-thumbnail" %>
</div>
</div>
<div class="form-inputs">
<%= f.input :item_code %>
<%= f.input :name %>
<%= f.input :alt_name %>
<%= f.input :type %>
<%= f.input :account_id, :label => "Account type", :collection => Account.collection %>
<%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %>
<div class="col-md-8">
<div class="form-inputs">
<%= f.input :item_code %>
<%= f.input :name %>
<%= f.input :alt_name %>
<%= f.input :type %>
<%= f.input :account_id, :label => "Account type", :collection => Account.collection %>
<%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %>
<%= f.input :min_qty %>
<%= f.input :min_selectable_item %>
<%= f.input :max_selectable_item %>
<%= f.input :min_qty %>
<%= f.input :min_selectable_item %>
<%= f.input :max_selectable_item %>
</div>
</div>
<div class="form-actions">

View File

@@ -1,16 +1,23 @@
<%= simple_form_for([:settings,@category, @settings_menu_item]) do |f| %>
<%= f.error_notification %>
<div class="col-md-4">
<div class="menu-item-img">
<%= f.file_field :image_path, :class => "img-thumbnail" %>
</div>
</div>
<div class="form-inputs">
<%= f.input :item_code %>
<%= f.input :name %>
<%= f.input :alt_name %>
<%= f.input :type %>
<%= f.input :account_id, :label => "Account type", :collection => Account.collection %>
<%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %>
<%= f.input :min_qty %>
<%= f.input :min_selectable_item %>
<%= f.input :max_selectable_item %>
<div class="col-md-8">
<div class="form-inputs">
<%= f.input :item_code %>
<%= f.input :name %>
<%= f.input :alt_name %>
<%= f.input :type %>
<%= f.input :account_id, :label => "Account type", :collection => Account.collection %>
<%= f.input :menu_item_id, :label => "Parent Menu Item", :collection => MenuItem.collection %>
<%= f.input :min_qty %>
<%= f.input :min_selectable_item %>
<%= f.input :max_selectable_item %>
</div>
</div>
<div class="form-actions">

View File

@@ -2,7 +2,6 @@
<%= render 'form', settings_menu_item: @settings_menu_item %>-->
<div class="span12">
<div class="page-header">
<ul class="breadcrumb">

View File

@@ -6,6 +6,8 @@ require 'rails/all'
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require 'carrierwave/orm/activerecord'
module SXRestaurants
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.