Commit 4872138e by Truong Ba Dieu

Refactor syntax ruby

parent 85209882
...@@ -69,7 +69,7 @@ gem 'kaminari', '0.16.3' ...@@ -69,7 +69,7 @@ gem 'kaminari', '0.16.3'
# cron job # cron job
gem 'whenever', :require => false gem 'whenever', :require => false
gem 'sidekiq' # background job. run server bundle exec sidekiq
# upload source # upload source
gem 'capistrano', '~> 3.1.0' gem 'capistrano', '~> 3.1.0'
...@@ -95,6 +95,8 @@ group :development, :test do ...@@ -95,6 +95,8 @@ group :development, :test do
gem 'rspec-mocks' gem 'rspec-mocks'
gem 'rspec-rails', '~> 3.0.1' gem 'rspec-rails', '~> 3.0.1'
gem 'rspec-support' gem 'rspec-support'
gem "pry" # debug gem "pry" # debug . put in file debug require 'pry' , binding.pry
gem "quiet_assets" gem "quiet_assets"
gem 'rubocop', require: false # check syntax code. rubocop [file]
end end
\ No newline at end of file
...@@ -66,6 +66,9 @@ GEM ...@@ -66,6 +66,9 @@ GEM
arbre (1.0.3) arbre (1.0.3)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
arel (6.0.2) arel (6.0.2)
ast (2.0.0)
astrolabe (1.3.1)
parser (~> 2.2)
autoprefixer-rails (5.2.1) autoprefixer-rails (5.2.1)
execjs execjs
json json
...@@ -103,6 +106,8 @@ GEM ...@@ -103,6 +106,8 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
xpath (~> 2.0) xpath (~> 2.0)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.6) childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2) chronic (0.10.2)
...@@ -116,6 +121,7 @@ GEM ...@@ -116,6 +121,7 @@ GEM
coffee-script-source (1.9.1.1) coffee-script-source (1.9.1.1)
colorize (0.7.7) colorize (0.7.7)
columnize (0.9.0) columnize (0.9.0)
connection_pool (2.2.0)
daemons (1.2.3) daemons (1.2.3)
database_cleaner (1.4.1) database_cleaner (1.4.1)
debug_inspector (0.0.2) debug_inspector (0.0.2)
...@@ -165,6 +171,7 @@ GEM ...@@ -165,6 +171,7 @@ GEM
has_scope (0.6.0) has_scope (0.6.0)
actionpack (>= 3.2, < 5) actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5) activesupport (>= 3.2, < 5)
hitimes (1.2.2)
i18n (0.7.0) i18n (0.7.0)
inherited_resources (1.6.0) inherited_resources (1.6.0)
actionpack (>= 3.2, < 5) actionpack (>= 3.2, < 5)
...@@ -209,8 +216,11 @@ GEM ...@@ -209,8 +216,11 @@ GEM
nokogiri (1.6.6.2) nokogiri (1.6.6.2)
mini_portile (~> 0.6.0) mini_portile (~> 0.6.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
polyamorous (1.2.0) polyamorous (1.2.0)
activerecord (>= 3.0) activerecord (>= 3.0)
powerpack (0.1.1)
pry (0.10.1) pry (0.10.1)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
...@@ -246,6 +256,7 @@ GEM ...@@ -246,6 +256,7 @@ GEM
activesupport (= 4.2.1) activesupport (= 4.2.1)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2) rake (10.4.2)
ransack (1.6.6) ransack (1.6.6)
actionpack (>= 3.0) actionpack (>= 3.0)
...@@ -254,6 +265,9 @@ GEM ...@@ -254,6 +265,9 @@ GEM
i18n i18n
polyamorous (~> 1.2) polyamorous (~> 1.2)
rdoc (4.2.0) rdoc (4.2.0)
redis (3.2.1)
redis-namespace (1.5.2)
redis (~> 3.0, >= 3.0.4)
request_store (1.1.0) request_store (1.1.0)
responders (2.1.0) responders (2.1.0)
railties (>= 4.2.0, < 5) railties (>= 4.2.0, < 5)
...@@ -280,8 +294,15 @@ GEM ...@@ -280,8 +294,15 @@ GEM
rspec-mocks (~> 3.0.0) rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0) rspec-support (~> 3.0.0)
rspec-support (3.0.4) rspec-support (3.0.4)
rubocop (0.32.1)
astrolabe (~> 1.3)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-growl (4.1) ruby-growl (4.1)
uuid (~> 2.3, >= 2.3.5) uuid (~> 2.3, >= 2.3.5)
ruby-progressbar (1.7.5)
rubyzip (1.1.7) rubyzip (1.1.7)
sass (3.4.16) sass (3.4.16)
sass-rails (5.0.3) sass-rails (5.0.3)
...@@ -300,6 +321,12 @@ GEM ...@@ -300,6 +321,12 @@ GEM
websocket (~> 1.0) websocket (~> 1.0)
shoulda-matchers (2.8.0) shoulda-matchers (2.8.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
sidekiq (3.4.2)
celluloid (~> 0.16.0)
connection_pool (~> 2.2, >= 2.2.0)
json (~> 1.0)
redis (~> 3.2, >= 3.2.1)
redis-namespace (~> 1.5, >= 1.5.2)
slim (3.0.6) slim (3.0.6)
temple (~> 0.7.3) temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1) tilt (>= 1.3.3, < 2.1)
...@@ -325,6 +352,8 @@ GEM ...@@ -325,6 +352,8 @@ GEM
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1) tilt (1.4.1)
timeliness (0.3.7) timeliness (0.3.7)
timers (4.0.1)
hitimes
turbolinks (2.5.3) turbolinks (2.5.3)
coffee-rails coffee-rails
turnip (1.3.1) turnip (1.3.1)
...@@ -399,11 +428,13 @@ DEPENDENCIES ...@@ -399,11 +428,13 @@ DEPENDENCIES
rspec-mocks rspec-mocks
rspec-rails (~> 3.0.1) rspec-rails (~> 3.0.1)
rspec-support rspec-support
rubocop
ruby-growl ruby-growl
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
selenium-webdriver selenium-webdriver
shoulda-matchers shoulda-matchers
sidekiq
slim slim
spring spring
thin thin
......
ActiveAdmin.register_page "Dashboard" do ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") } menu priority: 1, label: proc{ I18n.t('active_admin.dashboard') }
content title: proc{ I18n.t("active_admin.dashboard") } do content title: proc{ I18n.t('active_admin.dashboard') } do
div class: "blank_slate_container", id: "dashboard_default_message" do div class: 'blank_slate_container', id: 'dashboard_default_message' do
span class: "blank_slate" do span class: 'blank_slate' do
span I18n.t("active_admin.dashboard_welcome.welcome") span I18n.t('active_admin.dashboard_welcome.welcome')
small I18n.t("active_admin.dashboard_welcome.call_to_action") small I18n.t('active_admin.dashboard_welcome.call_to_action')
end end
end end
...@@ -14,7 +14,7 @@ ActiveAdmin.register_page "Dashboard" do ...@@ -14,7 +14,7 @@ ActiveAdmin.register_page "Dashboard" do
# #
# columns do # columns do
# column do # column do
# panel "Recent Posts" do # panel 'Recent Posts' do
# ul do # ul do
# Post.recent(5).map do |post| # Post.recent(5).map do |post|
# li link_to(post.title, admin_post_path(post)) # li link_to(post.title, admin_post_path(post))
...@@ -24,8 +24,8 @@ ActiveAdmin.register_page "Dashboard" do ...@@ -24,8 +24,8 @@ ActiveAdmin.register_page "Dashboard" do
# end # end
# column do # column do
# panel "Info" do # panel 'Info' do
# para "Welcome to ActiveAdmin." # para 'Welcome to ActiveAdmin.'
# end # end
# end # end
# end # end
......
...@@ -7,7 +7,6 @@ ActiveAdmin.register Order do ...@@ -7,7 +7,6 @@ ActiveAdmin.register Order do
filter :state, as: :select, collection: proc{ Order.states.map{ |k,v| [k, v] } } filter :state, as: :select, collection: proc{ Order.states.map{ |k,v| [k, v] } }
filter :created_at filter :created_at
form do |f| form do |f|
f.inputs do f.inputs do
f.input :pid, input_html: { disabled: true } f.input :pid, input_html: { disabled: true }
......
...@@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base ...@@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
# rescue for gem pundit # rescue for gem pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
add_breadcrumb "Home", :root_path add_breadcrumb 'Home', :root_path
def get_categories def get_categories
@categories = Category.featured @categories = Category.featured
...@@ -21,18 +21,19 @@ class ApplicationController < ActionController::Base ...@@ -21,18 +21,19 @@ class ApplicationController < ActionController::Base
def authenticate_admin_user! def authenticate_admin_user!
authenticate_user! authenticate_user!
unless current_user.has_role?(:admin) unless current_user.has_role?(:admin)
redirect_to root_path, error: "This area is restricted to administrators only." redirect_to root_path, error: 'This area is restricted to administrators only.'
end end
end end
private private
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:name) devise_parameter_sanitizer.for(:sign_up).push(:name)
devise_parameter_sanitizer.for(:account_update).push(:name) devise_parameter_sanitizer.for(:account_update).push(:name)
end end
def user_not_authorized def user_not_authorized
flash[:notice] = "You are not authorized to perform this action." flash[:notice] = 'You are not authorized to perform this action.'
redirect_to(request.referrer || root_path) redirect_to(request.referrer || root_path)
end end
......
...@@ -7,4 +7,4 @@ class CategoriesController < ApplicationController ...@@ -7,4 +7,4 @@ class CategoriesController < ApplicationController
add_breadcrumb @category.name add_breadcrumb @category.name
end end
end end
\ No newline at end of file
...@@ -8,18 +8,19 @@ class HomeController < ApplicationController ...@@ -8,18 +8,19 @@ class HomeController < ApplicationController
end end
def search def search
add_breadcrumb "Search" add_breadcrumb 'Search'
@solr_products = Product.solr_search(params) @solr_products = Product.solr_search(params)
@products = Product.where(id: @solr_products.map{ |h| h["id"] }) @products = Product.where(id: @solr_products.map{ |h| h['id'] })
end end
def cart def cart
add_breadcrumb "Cart" add_breadcrumb 'Cart'
render layout: "cart" render layout: 'cart'
end end
private private
def get_recommend def get_recommend
@recommend_products = Product.recommend @recommend_products = Product.recommend
end end
end end
\ No newline at end of file
...@@ -2,7 +2,7 @@ class OrdersController < ApplicationController ...@@ -2,7 +2,7 @@ class OrdersController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_order, only: [:show] before_action :set_order, only: [:show]
before_action -> { authorize(@order) }, only: [:show] before_action -> { authorize(@order) }, only: [:show]
layout "cart" layout 'cart'
def index def index
@orders = current_user.orders.order(completed_at: :desc).paginate(page: params[:page]) @orders = current_user.orders.order(completed_at: :desc).paginate(page: params[:page])
...@@ -29,6 +29,7 @@ class OrdersController < ApplicationController ...@@ -29,6 +29,7 @@ class OrdersController < ApplicationController
private private
def set_order def set_order
@order = Order.find(params[:id]) @order = Order.find(params[:id])
end end
......
...@@ -2,16 +2,16 @@ class ProductsController < ApplicationController ...@@ -2,16 +2,16 @@ class ProductsController < ApplicationController
include ApplicationHelper include ApplicationHelper
before_action :get_categories before_action :get_categories
before_action :authenticate_user!, :only => [:new, :create] before_action :authenticate_user!, only: [:new, :create]
after_action :verify_authorized, :only => [:new, :create] after_action :verify_authorized, only: [:new, :create]
def show def show
@product = Product.find(params[:id]) @product = Product.find(params[:id])
add_breadcrumb @product.category.try(:name), category_path(@product.category.try(:id)) add_breadcrumb(@product.category.try(:name), category_path(@product.category.try(:id)))
add_breadcrumb @product.title add_breadcrumb(@product.title)
fetch_social_info(@product.title, @product.title, @product.image.thumb("158x158#").url) fetch_social_info(@product.title, @product.title, @product.image.thumb('158x158#').url)
render layout: "share_social" render layout: 'share_social'
end end
def new def new
...@@ -24,16 +24,17 @@ class ProductsController < ApplicationController ...@@ -24,16 +24,17 @@ class ProductsController < ApplicationController
@product = Product.new(new_product_params) @product = Product.new(new_product_params)
if @product.save if @product.save
redirect_to category_path(@product.category), notice: "Product create successfully" redirect_to category_path(@product.category), notice: 'Product create successfully'
else else
render 'new' render 'new'
end end
end end
private private
def new_product_params def new_product_params
params[:product][:release_date] = Datetime.rstrptime(params[:product][:release_date], "%m/%d/%Y %H:%M %p") params[:product][:release_date] = DateTime.rstrptime(params[:product][:release_date], '%m/%d/%Y %H:%M %p')
params[:product][:public_date] = Datetime.rstrptime(params[:product][:public_date], "%m/%d/%Y %H:%M %p") params[:product][:public_date] = DateTime.rstrptime(params[:product][:public_date], '%m/%d/%Y %H:%M %p')
params.require(:product).permit(:stock, :pid, :title, :author, :publisher, :studio, :price, :currency, :category_id, :image, :release_date, :public_date, :recommend) params.require(:product).permit(:stock, :pid, :title, :author, :publisher, :studio, :price, :currency, :category_id, :image, :release_date, :public_date, :recommend)
end end
end end
\ No newline at end of file
ActiveRecord::Base.class_eval do ActiveRecord::Base.class_eval do
def to_hash(fields) def to_hash(fields = nil)
begin hash = {}
hash = {} fields.each do |field|
fields.each do |f| hash[field.to_sym] = send(field.to_sym)
hash[f.to_sym] = send(f.to_sym) end
end hash
hash
rescue rescue
{} {}
end
end end
end end
\ No newline at end of file
DateTime.instance_eval do DateTime.instance_eval do
def rstrftime(datetime = nil, type="%B %d, %Y", rescue_datetime=nil) def rstrftime(datetime = nil, type = '%B %d, %Y', rescue_datetime = nil)
begin datetime.strftime(type)
datetime.strftime(type)
rescue # try to strftime rescue_datetime when error rescue # try to strftime rescue_datetime when error
rescue_datetime.strftime(type) if rescue_datetime.is_a?(DateTime) || rescue_datetime.is_a?(Time) if rescue_datetime.is_a?(DateTime) || rescue_datetime.is_a?(Time)
end rescue_datetime.strftime(type)
end
end end
def rstrptime(str = nil, type="%Y-%m-%d", rescue_time=DateTime.now) def rstrptime(str = nil, type = '%Y-%m-%d', rescue_time = DateTime.now)
begin str.strptime(type)
str.strptime(type)
rescue rescue
rescue_time rescue_time
end
end end
end end
\ No newline at end of file
...@@ -3,7 +3,7 @@ class OrderDecorator < Draper::Decorator ...@@ -3,7 +3,7 @@ class OrderDecorator < Draper::Decorator
def pid_link def pid_link
if object.cart? if object.cart?
h.content_tag( :i, "Order not checkout" ) h.content_tag( :i, 'Order not checkout' )
else else
h.content_tag( :a, object.pid, href: order_path(object.id) ) h.content_tag( :a, object.pid, href: order_path(object.id) )
end end
...@@ -16,4 +16,4 @@ class OrderDecorator < Draper::Decorator ...@@ -16,4 +16,4 @@ class OrderDecorator < Draper::Decorator
object.state object.state
end end
end end
end end
\ No newline at end of file
...@@ -10,4 +10,3 @@ class ProductDecorator < Draper::Decorator ...@@ -10,4 +10,3 @@ class ProductDecorator < Draper::Decorator
link_to object.title, product_path(object.id) link_to object.title, product_path(object.id)
end end
end end
...@@ -4,4 +4,4 @@ class UserDecorator < Draper::Decorator ...@@ -4,4 +4,4 @@ class UserDecorator < Draper::Decorator
def edit_profile_link def edit_profile_link
h.content_tag(:a, object.name || object.email, href: edit_user_registration_path) h.content_tag(:a, object.name || object.email, href: edit_user_registration_path)
end end
end end
\ No newline at end of file
module ApplicationHelper module ApplicationHelper
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
def currency_number(price=0, currency="usd") def currency_number(price = 0, currency = 'usd')
"#{currency}#{price}" "#{currency}#{price}"
end end
......
module OrderHelper module OrderHelper
def current_order def current_order
if current_user.present? return nil if current_user.blank?
current_user.orders.where(state: Order.states[:cart]).first_or_create current_user.orders.where(state: Order.states[:cart]).first_or_create
else
nil
end
end end
end end
class UserMailer < ActionMailer::Base class UserMailer < ActionMailer::Base
default from: ENV["default_send_mail"] default from: ENV['default_send_mail']
add_template_helper(ApplicationHelper) add_template_helper(ApplicationHelper)
def success_checkout(current_order) def success_checkout(current_order)
@user = current_order.user @user = current_order.user
@order = current_order @order = current_order
mail to: @user.email, subject: "Venshop! Checkout successfully" mail to: @user.email, subject: 'Venshop! Checkout successfully'
end end
end end
...@@ -11,6 +11,7 @@ module Solr extend ActiveSupport::Concern ...@@ -11,6 +11,7 @@ module Solr extend ActiveSupport::Concern
end end
private private
def update_solr def update_solr
if solr_fields_change? if solr_fields_change?
self.class.rsolr.add fetch_solr_attr self.class.rsolr.add fetch_solr_attr
...@@ -28,38 +29,38 @@ module Solr extend ActiveSupport::Concern ...@@ -28,38 +29,38 @@ module Solr extend ActiveSupport::Concern
end end
def solr_fields_change? def solr_fields_change?
changed.any? {|field| solr_fields.include? field } changed.any? { |field| solr_fields.include? field }
end end
end end
module ClassMethods module ClassMethods
def solr_search(params={}) def solr_search(params = {})
params[:page] ||= 1 params[:page] ||= 1
keyword = refine_keyword(params[:keyword]) keyword = refine_keyword(params[:keyword])
res = rsolr.paginate params[:page], ENV["default_perpage"], 'select', :params => {:q => "*#{keyword}*"} res = rsolr.paginate params[:page], ENV['default_perpage'], 'select', :params => { q: "*#{keyword}*" }
fetch_result(res) fetch_result(res)
end end
def rsolr def rsolr
@rsolr ||= RSolr.connect :url => ENV["solr_url"] @rsolr ||= RSolr.connect :url => ENV['solr_url']
end end
private private
# refine some special chars can not accept from solr # refine some special chars can not accept from solr
def refine_keyword(keyword="") def refine_keyword(keyword = '')
%w(+ - && || ! ( ) { } [ ] ^ " ~ * ? : \\).each do |s| %w(+ - && || ! ( ) { } [ ] ^ " ~ * ? : \\).each do |s|
keyword = keyword.gsub(s, " ") keyword = keyword.gsub(s, ' ')
end end
keyword keyword
end end
def fetch_result(response) def fetch_result(response)
begin response['response']['docs']
response["response"]["docs"]
rescue rescue
[] []
end
end end
end end
end end
\ No newline at end of file
...@@ -6,7 +6,7 @@ module UserRole extend ActiveSupport::Concern ...@@ -6,7 +6,7 @@ module UserRole extend ActiveSupport::Concern
before_save :default_role before_save :default_role
def default_role def default_role
self.add_role(:user) if self.roles.blank? add_role(:user) if roles.blank?
end end
end end
......
...@@ -8,14 +8,13 @@ class LineItem < ActiveRecord::Base ...@@ -8,14 +8,13 @@ class LineItem < ActiveRecord::Base
after_save :trigger_recalculate after_save :trigger_recalculate
before_destroy :trigger_calculate_order before_destroy :trigger_calculate_order
private private
def trigger_recalculate def trigger_recalculate
if quantity_changed? return unless quantity_changed?
order.recalculate order.recalculate
change_square = quantity - quantity_was change_square = quantity - quantity_was
product.substract_stock(change_square) product.substract_stock(change_square)
end
end end
# validate quantity line_item with product stock # validate quantity line_item with product stock
...@@ -23,7 +22,7 @@ class LineItem < ActiveRecord::Base ...@@ -23,7 +22,7 @@ class LineItem < ActiveRecord::Base
return false if quantity.blank? || product_id.blank? return false if quantity.blank? || product_id.blank?
change_square = quantity - quantity_was change_square = quantity - quantity_was
if change_square > product.try(:stock) if change_square > product.try(:stock)
self.errors.add(:quantity, "Product #{product.try(:title)} is not enough in stock") errors.add(:quantity, "Product #{product.try(:title)} is not enough in stock")
return false return false
end end
end end
......
...@@ -8,18 +8,18 @@ class Order < ActiveRecord::Base ...@@ -8,18 +8,18 @@ class Order < ActiveRecord::Base
def recalculate def recalculate
count = line_items.sum(:quantity) count = line_items.sum(:quantity)
self.update_attributes( update_attributes(
item_count: count, item_count: count,
item_total: self.reload.line_items.inject(0) {|sum, item| sum + item.quantity*item.price } item_total: self.reload.line_items.inject(0) { |sum, item| sum + item.quantity * item.price }
) )
end end
def checkout def checkout
pid = generate_token update_attributes(state: Order.states[:checkout], pid: generate_token, completed_at: DateTime.now)
self.update_attributes(state: Order.states[:checkout], pid: pid, completed_at: DateTime.now)
end end
private private
def generate_token def generate_token
loop do loop do
random_token = SecureRandom.urlsafe_base64(nil, false) random_token = SecureRandom.urlsafe_base64(nil, false)
......
...@@ -8,12 +8,12 @@ class Product < ActiveRecord::Base ...@@ -8,12 +8,12 @@ class Product < ActiveRecord::Base
# default 'public/images/product_default.jpg' # default 'public/images/product_default.jpg'
end end
self.per_page = ENV["default_perpage"] self.per_page = ENV['default_perpage']
validates :pid, :title, :price, :image, :category_id, :stock, :release_date, :public_date, presence: true validates :pid, :title, :price, :image, :category_id, :stock, :release_date, :public_date, presence: true
validates :pid, uniqueness: true validates :pid, uniqueness: true
validates :price, numericality: true validates :price, numericality: true
validates_datetime :public_date, :on_or_after => :release_date validates_datetime :public_date, on_or_after: :release_date
scope :recommend, -> { where(recommend: true) } scope :recommend, -> { where(recommend: true) }
...@@ -22,7 +22,7 @@ class Product < ActiveRecord::Base ...@@ -22,7 +22,7 @@ class Product < ActiveRecord::Base
end end
def substract_stock(change) def substract_stock(change)
self.update_attributes(stock: stock - change) update_attributes(stock: stock - change)
end end
def solr_fields def solr_fields
......
class Role < ActiveRecord::Base class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles has_and_belongs_to_many :users, join_table: :users_roles
belongs_to :resource, :polymorphic => true belongs_to :resource, polymorphic: true
validates :resource_type, validates :resource_type,
:inclusion => { :in => Rolify.resource_types }, inclusion: { :in => Rolify.resource_types },
:allow_nil => true allow_nil: true
scopify scopify
end end
...@@ -12,22 +12,22 @@ class CartService ...@@ -12,22 +12,22 @@ class CartService
line_item = order.line_items.where(product_id: product.id, price: product.price).first_or_create line_item = order.line_items.where(product_id: product.id, price: product.price).first_or_create
line_item.quantity += params[:quantity].to_i line_item.quantity += params[:quantity].to_i
if line_item.save if line_item.save
ResultMessage.new({ type: :notice, content: "Add to cart successfully"}) ResultMessage.new({ type: :notice, content: 'Add to cart successfully'})
else else
ResultMessage.new({ type: :error, content: "Something went wrong"}) ResultMessage.new({ type: :error, content: 'Something went wrong'})
end end
else else
ResultMessage.new({ type: :error, content: "Product is not enough in stock"}) ResultMessage.new({ type: :error, content: 'Product is not enough in stock'})
end end
end end
def checkout def checkout
if order.line_items.blank? if order.line_items.blank?
ResultMessage.new({ type: :error, content: "Your cart is empty"}) ResultMessage.new({ type: :error, content: 'Your cart is empty'})
else else
if order.checkout if order.checkout
UserMailer.success_checkout(order).deliver UserMailer.success_checkout(order).deliver
ResultMessage.new({ type: :notice, content: "Checkout successfully"}) ResultMessage.new({ type: :notice, content: 'Checkout successfully'})
else else
ResultMessage.new({ type: :error, content: "Checkout fail. #{order.errors.full_messages.join(', ')}"}) ResultMessage.new({ type: :error, content: "Checkout fail. #{order.errors.full_messages.join(', ')}"})
end end
...@@ -36,7 +36,7 @@ class CartService ...@@ -36,7 +36,7 @@ class CartService
def update_cart(params) def update_cart(params)
if order.update_attributes(params) if order.update_attributes(params)
ResultMessage.new({ type: :notice, content: "Update cart successfully"}) ResultMessage.new({ type: :notice, content: 'Update cart successfully'})
else else
ResultMessage.new({ type: :error, content: "Update cart fail. #{order.errors.full_messages.join(', ')}"}) ResultMessage.new({ type: :error, content: "Update cart fail. #{order.errors.full_messages.join(', ')}"})
end end
......
...@@ -12,7 +12,7 @@ class CronjobService ...@@ -12,7 +12,7 @@ class CronjobService
aws_object = vaccum.item_lookup(item_id: object.pid) aws_object = vaccum.item_lookup(item_id: object.pid)
aws_object = vaccum.to_attr(aws_object) aws_object = vaccum.to_attr(aws_object)
if aws_object.present? if aws_object.present?
attributes = aws_object.select{|key, value| fields.include?(key.to_s) } attributes = aws_object.select{ |key, value| fields.include?(key.to_s) }
object.update_attributes(attributes) object.update_attributes(attributes)
end end
end end
......
class VacuumAwsService class VacuumAwsService
def initialize(options={}) def initialize(options={})
@request = Vacuum.new(options.fetch(:country_code, "GB")) @request = Vacuum.new(options.fetch(:country_code, 'GB'))
@request.configure( @request.configure(
aws_access_key_id: ENV['aws_access_key_id'], aws_access_key_id: ENV['aws_access_key_id'],
aws_secret_access_key: ENV['aws_secret_access_key'], aws_secret_access_key: ENV['aws_secret_access_key'],
...@@ -15,14 +15,12 @@ class VacuumAwsService ...@@ -15,14 +15,12 @@ class VacuumAwsService
# search item by pid # search item by pid
def item_lookup(options={}) def item_lookup(options={})
begin response = request.item_lookup(
response = request.item_lookup( query: default_query_options.merge('ItemId' => options[:item_id])
query: default_query_options.merge('ItemId' => options[:item_id]) )
) parse_item(response)
parse_item(response)
rescue rescue
nil nil
end
end end
# search items # search items
...@@ -32,46 +30,41 @@ class VacuumAwsService ...@@ -32,46 +30,41 @@ class VacuumAwsService
end end
def parse_items(response) def parse_items(response)
begin response.to_h['ItemSearchResponse']['Items']['Item']
response.to_h["ItemSearchResponse"]["Items"]["Item"]
rescue rescue
false false
end
end end
def parse_item(response) def parse_item(response)
begin response.to_h['ItemLookupResponse']['Items']['Item']
response.to_h["ItemLookupResponse"]["Items"]["Item"]
rescue rescue
nil nil
end
end end
def to_attr(item) def to_attr(item)
# only get product have pid, title, price # only get product have pid, title, price
if validate(item) unless validate?(item)
{ {
pid: item["ASIN"], pid: item['ASIN'],
title: item["ItemAttributes"]["Title"], title: item['ItemAttributes']['Title'],
author: item["ItemAttributes"]["Author"], author: item['ItemAttributes']['Author'],
publisher: item["ItemAttributes"]["Publisher"], publisher: item['ItemAttributes']['Publisher'],
studio: item["ItemAttributes"]["Studio"], studio: item['ItemAttributes']['Studio'],
price: item["ItemAttributes"]["ListPrice"]["FormattedPrice"][1..-1].to_f, price: item['ItemAttributes']['ListPrice']['FormattedPrice'][1..-1].to_f,
currency: item["ItemAttributes"]["ListPrice"]["FormattedPrice"].to_s.first, currency: item['ItemAttributes']['ListPrice']['FormattedPrice'].to_s.first,
release_date: ::DateTime.rstrptime(item["ItemAttributes"]["ReleaseDate"], "%Y-%m-%d"), release_date: ::DateTime.rstrptime(item['ItemAttributes']['ReleaseDate'], '%Y-%m-%d'),
public_date: ::DateTime.rstrptime(item["ItemAttributes"]["PublicationDate"], "%Y-%m-%d"), public_date: ::DateTime.rstrptime(item['ItemAttributes']['PublicationDate'], '%Y-%m-%d'),
image_url: item["LargeImage"]["URL"] image_url: item['LargeImage']['URL']
} }
end end
end end
private private
def validate(item)
item.present? && item["ASIN"].present? && def validate?(item)
item["ItemAttributes"]["Title"].present? && item.present? && item['ASIN'].present? &&
item["ItemAttributes"]["ListPrice"].present? && item['ItemAttributes']['Title'].present? &&
item["LargeImage"].present? item['ItemAttributes']['ListPrice'].present? &&
item['LargeImage'].present?
end end
end end
#categories #categories
- if @products.present? - if @products.present?
.products .products
= render partial: "products/item", collection: @products, as: :product = render partial: 'products/item', collection: @products, as: :product
.text-center .text-center
= will_paginate @products = will_paginate @products
\ No newline at end of file
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
- if current_order.line_items.blank? - if current_order.line_items.blank?
.text-center .text-center
'You cart is empty. 'You cart is empty.
= link_to "Continue shopping", root_path = link_to 'Continue shopping', root_path
- else - else
= form_for current_order, html:{ class: "form-horizontal" } do |f| = form_for current_order, html:{ class: 'form-horizontal' } do |f|
#error_explanation #error_explanation
- current_order.line_items.each do |i| - current_order.line_items.each do |i|
- if i.errors.any? - if i.errors.any?
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
td= i.index+1 td= i.index+1
td= i.object.product.title td= i.object.product.title
td td
= i.number_field :quantity, class: "form-control item-quantity", min: 1 = i.number_field :quantity, class: 'form-control item-quantity', min: 1
span= "(available: #{i.object.product.stock})" span= "(available: #{i.object.product.stock})"
td td
span.item-price= i.object.price span.item-price= i.object.price
...@@ -46,13 +46,13 @@ ...@@ -46,13 +46,13 @@
span.total-cart= current_order.item_total span.total-cart= current_order.item_total
span= current_order.line_items.first.try(:product).try(:currency) span= current_order.line_items.first.try(:product).try(:currency)
td td
= f.submit "Update Cart", class: "btn btn-primary" = f.submit 'Update Cart', class: 'btn btn-primary'
tr tr
td(colspan=5) td(colspan=5)
td td
.text-center .text-center
= link_to "Checkout", checkout_orders_path, class: "btn btn-success btn-lg" = link_to 'Checkout', checkout_orders_path, class: 'btn btn-success btn-lg'
br br
i i
'(You must update change before checkout cart) '(You must update change before checkout cart)
\ No newline at end of file
- if @recommend_products.present? - if @recommend_products.present?
h3 Recommend Products h3 Recommend Products
.row.recommends .row.recommends
= render partial: "products/recommend_item", collection: @recommend_products, as: :product = render partial: 'products/recommend_item', collection: @recommend_products, as: :product
hr hr
- if @products.present? - if @products.present?
.products .products
h3 Products h3 Products
= render partial: "products/item", collection: @products, as: :product = render partial: 'products/item', collection: @products, as: :product
.text-center .text-center
= will_paginate @products = will_paginate @products
\ No newline at end of file
h4= "Search with keyword '#{params[:keyword]}'" h4= "Search with keyword '#{params[:keyword]}'"
- if @products.present? - if @products.present?
.products .products
= render partial: "products/item", collection: @products, as: :product = render partial: 'products/item', collection: @products, as: :product
.text-center .text-center
= will_paginate @solr_products = will_paginate @solr_products
\ No newline at end of file
nav.navbar.navbar-inverse nav.navbar.navbar-inverse
.container .container
.navbar-header .navbar-header
button.navbar-toggle[type="button" data-toggle="collapse" data-target=".navbar-collapse"] button.navbar-toggle[type='button' data-toggle='collapse' data-target='.navbar-collapse']
span.sr-only span.sr-only
| Toggle navigation | Toggle navigation
span.icon-bar span.icon-bar
...@@ -9,7 +9,7 @@ nav.navbar.navbar-inverse ...@@ -9,7 +9,7 @@ nav.navbar.navbar-inverse
span.icon-bar span.icon-bar
h1.logo h1.logo
a(href="#{root_path}" class='navbar-brand') a(href="#{root_path}" class='navbar-brand')
= image_tag "logo.png" = image_tag 'logo.png'
'Venshop 'Venshop
.collapse.navbar-collapse .collapse.navbar-collapse
ul.nav.navbar-nav ul.nav.navbar-nav
...@@ -22,9 +22,9 @@ nav.navbar.navbar-inverse ...@@ -22,9 +22,9 @@ nav.navbar.navbar-inverse
li li
= current_user.decorate.edit_profile_link = current_user.decorate.edit_profile_link
li li
= link_to "Logout", destroy_user_session_path, method: 'delete' = link_to 'Logout', destroy_user_session_path, method: 'delete'
- else - else
li li
= link_to "Login", new_user_session_path = link_to 'Login', new_user_session_path
li li
= link_to "Sign up", new_user_registration_path = link_to 'Sign up', new_user_registration_path
\ No newline at end of file \ No newline at end of file
- if policy(:product).new? - if policy(:product).new?
li= link_to "New product", new_product_path li= link_to 'New product', new_product_path
- if current_user.present? - if current_user.present?
li= link_to "My orders", orders_path li= link_to 'My orders', orders_path
doctype html doctype html
html html
head head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"] meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title title
= @title || "Venshop" = @title || 'Venshop'
= favicon_link_tag 'favicon.ico' = favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png' = favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag "application", "data-turbolinks-track" => true = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags
body body
#wrap #wrap
......
doctype html doctype html
html html
head head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"] meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title title
= @title || "Venshop" = @title || 'Venshop'
= favicon_link_tag 'favicon.ico' = favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png' = favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag "application", "data-turbolinks-track" => true = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags
body body
#wrap #wrap
......
doctype html doctype html
html html
head head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"] meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title title
= @title || "Venshop" = @title || 'Venshop'
= favicon_link_tag 'favicon.ico' = favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png' = favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag "application", "data-turbolinks-track" => true = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags
body body
#wrap #wrap
......
.product-form .product-form
= form_for @product, html:{class: "form-horizontal"} do |f| = form_for @product, html:{ class: 'form-horizontal' } do |f|
- if @product.errors.any? - if @product.errors.any?
#error_explanation #error_explanation
h3= "#{pluralize(@product.errors.count, "error")} prohibited this product from being saved:" h3= "#{pluralize(@product.errors.count, 'error')} prohibited this product from being saved:"
ul ul
- @product.errors.full_messages.each do |msg| - @product.errors.full_messages.each do |msg|
li= msg li= msg
= f.hidden_field :currency, value: '£' = f.hidden_field :currency, value: '£'
.form-group .form-group
= f.label :pid, class:"control-label col-sm-3" = f.label :pid, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :pid, class: "form-control" = f.text_field :pid, class: 'form-control'
.form-group .form-group
= f.label :title, class:"control-label col-sm-3" = f.label :title, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :title, class: "form-control" = f.text_field :title, class: 'form-control'
.form-group .form-group
= f.label :stock, class:"control-label col-sm-3" = f.label :stock, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.number_field :stock, class: "form-control" = f.number_field :stock, class: 'form-control'
.form-group .form-group
= f.label :author, class:"control-label col-sm-3" = f.label :author, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :author, class: "form-control" = f.text_field :author, class: 'form-control'
.form-group .form-group
= f.label :publisher, class:"control-label col-sm-3" = f.label :publisher, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :publisher, class: "form-control" = f.text_field :publisher, class: 'form-control'
.form-group .form-group
= f.label :studio, class:"control-label col-sm-3" = f.label :studio, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :studio, class: "form-control" = f.text_field :studio, class: 'form-control'
.form-group .form-group
= f.label :price, class:"control-label col-sm-3" = f.label :price, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.number_field :price, class: "form-control" = f.number_field :price, class: 'form-control'
.form-group .form-group
= f.label :category_id, class:"control-label col-sm-3" = f.label :category_id, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.select :category_id, options_for_select(categories_options, @product.category_id), {}, class: "form-control" = f.select :category_id, options_for_select(categories_options, @product.category_id), {}, class: 'form-control'
.form-group .form-group
= f.label "Image", class:"control-label col-sm-3", for: "product_image" = f.label 'Image', class:'control-label col-sm-3', for: 'product_image'
.col-sm-9 .col-sm-9
- if !@product.new_record? && @product.image.present? - if !@product.new_record? && @product.image.present?
= image_tag @product.image.thumb('200x200#') = image_tag @product.image.thumb('200x200#')
= f.file_field :image = f.file_field :image
.form-group .form-group
= f.label :release_date, class:"control-label col-sm-3" = f.label :release_date, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
.input-group.date.datetimepicker .input-group.date.datetimepicker
input(type='text' class="form-control" name="product[release_date]") input(type='text' class='form-control' name='product[release_date]')
span.input-group-addon span.input-group-addon
span.glyphicon.glyphicon-calendar span.glyphicon.glyphicon-calendar
.form-group .form-group
= f.label :public_date, class:"control-label col-sm-3" = f.label :public_date, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
.input-group.date.datetimepicker .input-group.date.datetimepicker
input(type='text' class="form-control" name="product[public_date]") input(type='text' class='form-control' name='product[public_date]')
span.input-group-addon span.input-group-addon
span.glyphicon.glyphicon-calendar span.glyphicon.glyphicon-calendar
.form-group .form-group
= f.label :recommend, class:"control-label col-sm-3" = f.label :recommend, class:'control-label col-sm-3'
.col-sm-9 .col-sm-9
.checkbox .checkbox
= f.check_box :recommend, class:'mar-l-0' = f.check_box :recommend, class:'mar-l-0'
.form-group .form-group
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= f.submit "Save", class: "btn btn-primary" = f.submit 'Save', class: 'btn btn-primary'
h1 New Product h1 New Product
= render "form" = render 'form'
\ No newline at end of file \ No newline at end of file
script(type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55af38b64560cb34" async="async") script(type='text/javascript' src='//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55af38b64560cb34' async='async')
#product #product
h4= @product.title h4= @product.title
= image_tag @product.image.thumb("110x86#").url = image_tag @product.image.thumb('110x86#').url
.content .content
p= "Item ID: #{@product.pid}" p= "Item ID: #{@product.pid}"
p= "Price #{currency_number(@product.price, @product.currency)}" p= "Price #{currency_number(@product.price, @product.currency)}"
...@@ -12,10 +12,10 @@ script(type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pub ...@@ -12,10 +12,10 @@ script(type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pub
p= "Publisher: #{@product.publisher}" p= "Publisher: #{@product.publisher}"
p= "Studio: #{@product.studio}" p= "Studio: #{@product.studio}"
p= "Stock: #{@product.stock}" p= "Stock: #{@product.stock}"
= form_tag add_to_cart_orders_path, class: "form-inline" do |f| = form_tag add_to_cart_orders_path, class: 'form-inline' do |f|
.form-group .form-group
= number_field_tag :quantity, 1, class: "form-control" = number_field_tag :quantity, 1, class: 'form-control'
= hidden_field_tag :product_id, @product.id = hidden_field_tag :product_id, @product.id
= submit_tag "Add to cart", class: "btn btn-primary xs-mar-top-10" = submit_tag 'Add to cart', class: 'btn btn-primary xs-mar-top-10'
.mar-top-20 .mar-top-20
.addthis_native_toolbox .addthis_native_toolbox
\ No newline at end of file
- flash.each do |name, msg| - flash.each do |name, msg|
- if msg.is_a?(String) - if msg.is_a?(String)
.alert(class="alert-#{name == 'notice' ? 'success' : 'danger'}") .alert(class="alert-#{name == 'notice' ? 'success' : 'danger'}")
button.close(data-dismiss="alert" aria-hidden="true")&times; button.close(data-dismiss='alert' aria-hidden='true')&times;
= content_tag :div, msg, :id => "flash_#{name}" = content_tag :div, msg, :id => "flash_#{name}"
#search-bar #search-bar
= form_tag search_path, class: "form-horizontal", method: "GET" do |f| = form_tag search_path, class: 'form-horizontal', method: 'GET' do |f|
.row .row
.col-sm-10.col-xs-8 .col-sm-10.col-xs-8
= text_field_tag :keyword, params[:keyword], placeholder: "Keyword", class: "form-control" = text_field_tag :keyword, params[:keyword], placeholder: 'Keyword', class: 'form-control'
.col-sm-2.col-xs-4 .col-sm-2.col-xs-4
= submit_tag "Search", class: "btn btn-primary" = submit_tag 'Search', class: 'btn btn-primary'
...@@ -7,5 +7,5 @@ h2 ...@@ -7,5 +7,5 @@ h2
br br
= f.email_field :email, autofocus: true = f.email_field :email, autofocus: true
.actions .actions
= f.submit "Resend confirmation instructions" = f.submit 'Resend confirmation instructions'
= render "users/shared/links" = render 'users/shared/links'
...@@ -4,13 +4,13 @@ h2 ...@@ -4,13 +4,13 @@ h2
= devise_error_messages! = devise_error_messages!
= f.hidden_field :reset_password_token = f.hidden_field :reset_password_token
.field .field
= f.label :password, "New password" = f.label :password, 'New password'
br br
= f.password_field :password, autofocus: true, autocomplete: "off" = f.password_field :password, autofocus: true, autocomplete: 'off'
.field .field
= f.label :password_confirmation, "Confirm new password" = f.label :password_confirmation, 'Confirm new password'
br br
= f.password_field :password_confirmation, autocomplete: "off" = f.password_field :password_confirmation, autocomplete: 'off'
.actions .actions
= f.submit "Change my password" = f.submit 'Change my password'
= render "users/shared/links" = render 'users/shared/links'
...@@ -7,5 +7,5 @@ h2 ...@@ -7,5 +7,5 @@ h2
br br
= f.email_field :email, autofocus: true = f.email_field :email, autofocus: true
.actions .actions
= f.submit "Send me reset password instructions" = f.submit 'Send me reset password instructions'
= render "users/shared/links" = render 'users/shared/links'
.form-devise .form-devise
h2 h2
| Edit | Edit
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class:"form-horizontal" }) do |f| = form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class:'form-horizontal' }) do |f|
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= devise_error_messages! = devise_error_messages!
.form-group .form-group
= f.label :name, class: "control-label col-sm-3" = f.label :name, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :name, autofocus: true, class: "form-control" = f.text_field :name, autofocus: true, class: 'form-control'
.form-group .form-group
= f.label :email, class: "control-label col-sm-3" = f.label :email, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.email_field :email, class: "form-control" = f.email_field :email, class: 'form-control'
- if devise_mapping.confirmable? && resource.pending_reconfirmation? - if devise_mapping.confirmable? && resource.pending_reconfirmation?
div div
| Currently waiting confirmation for: | Currently waiting confirmation for:
= resource.unconfirmed_email = resource.unconfirmed_email
.form-group .form-group
= f.label :password, class: "control-label col-sm-3" = f.label :password, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control" = f.password_field :password, autocomplete: 'off', class: 'form-control'
i i
| (leave blank if you don't want to change it) | (leave blank if you don't want to change it)
.form-group .form-group
= f.label :password_confirmation, class: "control-label col-sm-3" = f.label :password_confirmation, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" = f.password_field :password_confirmation, autocomplete: 'off', class: 'form-control'
.form-group .form-group
= f.label :current_password, class: "control-label col-sm-3" = f.label :current_password, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.password_field :current_password, autocomplete: "off", class: "form-control" = f.password_field :current_password, autocomplete: 'off', class: 'form-control'
i i
| (we need your current password to confirm your changes) | (we need your current password to confirm your changes)
.form-group .form-group
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= f.submit "Update", class: "btn btn-primary" = f.submit 'Update', class: 'btn btn-primary'
.form-devise .form-devise
h2 h2
| Sign up | Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class:"form-horizontal" }) do |f| = form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class:'form-horizontal' }) do |f|
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= devise_error_messages! = devise_error_messages!
.form-group .form-group
= f.label :name, class: "control-label col-sm-3" = f.label :name, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.text_field :name, autofocus: true, class: "form-control" = f.text_field :name, autofocus: true, class: 'form-control'
.form-group .form-group
= f.label :email, class: "control-label col-sm-3" = f.label :email, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.email_field :email, class: "form-control" = f.email_field :email, class: 'form-control'
.form-group .form-group
= f.label :password, class: "control-label col-sm-3" = f.label :password, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control" = f.password_field :password, autocomplete: 'off', class: 'form-control'
- if @validatable - if @validatable
em em
| ( | (
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
.form-group .form-group
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= f.submit "Sign up", class: "btn btn-primary" = f.submit 'Sign up', class: 'btn btn-primary'
.clearfix .clearfix
br br
= render "users/shared/links" = render 'users/shared/links'
.form-devise .form-devise
h2 h2
| Log in | Log in
= form_for(resource, as: resource_name, url: session_path(resource_name), html: { class:"form-horizontal" }) do |f| = form_for(resource, as: resource_name, url: session_path(resource_name), html: { class:'form-horizontal' }) do |f|
.form-group .form-group
= f.label :email, class: "control-label col-sm-3" = f.label :email, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.email_field :email, autofocus: true, class: "form-control" = f.email_field :email, autofocus: true, class: 'form-control'
.form-group .form-group
= f.label :password, class: "control-label col-sm-3" = f.label :password, class: 'control-label col-sm-3'
.col-sm-9 .col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control" = f.password_field :password, autocomplete: 'off', class: 'form-control'
- if devise_mapping.rememberable? - if devise_mapping.rememberable?
.form-group .form-group
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
.form-group .form-group
.col-sm-offset-3.col-sm-9 .col-sm-offset-3.col-sm-9
= f.submit "Log in", class: "btn btn-primary" = f.submit 'Log in', class: 'btn btn-primary'
.clearfix .clearfix
br br
= render "users/shared/links" = render 'users/shared/links'
- if controller_name != 'sessions' - if controller_name != 'sessions'
= link_to "Log in", new_session_path(resource_name) = link_to 'Log in', new_session_path(resource_name)
br br
- if devise_mapping.registerable? && controller_name != 'registrations' - if devise_mapping.registerable? && controller_name != 'registrations'
= link_to "Sign up", new_registration_path(resource_name) = link_to 'Sign up', new_registration_path(resource_name)
br br
-#- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' -#- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
-# = link_to "Forgot your password?", new_password_path(resource_name) -# = link_to "Forgot your password?", new_password_path(resource_name)
......
...@@ -7,5 +7,5 @@ h2 ...@@ -7,5 +7,5 @@ h2
br br
= f.email_field :email, autofocus: true = f.email_field :email, autofocus: true
.actions .actions
= f.submit "Resend unlock instructions" = f.submit 'Resend unlock instructions'
= render "users/shared/links" = render 'users/shared/links'
class HardWorker
include Sidekiq::Worker
def perform
puts "It 's work"
end
end
\ No newline at end of file
...@@ -24,7 +24,7 @@ module VenShop ...@@ -24,7 +24,7 @@ module VenShop
# Do not swallow errors in after_commit/after_rollback callbacks. # Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true config.active_record.raise_in_transactional_callbacks = true
config.autoload_paths += %W(#{config.root}/app/services #{config.root}/lib) config.autoload_paths += %W(#{config.root}/app/services #{config.root}/app/workers #{config.root}/lib)
config.to_prepare do config.to_prepare do
Dir.glob(File.join(File.dirname(__FILE__), "../app/core_extensions/*_extension.rb")) do |c| Dir.glob(File.join(File.dirname(__FILE__), "../app/core_extensions/*_extension.rb")) do |c|
# Rails.configuration.cache_classes ? require(c) : load(c) # Rails.configuration.cache_classes ? require(c) : load(c)
......
aws_access_key_id: "AKIAIAJR65JO6EIPQWTA" aws_access_key_id: 'AKIAIAJR65JO6EIPQWTA'
aws_secret_access_key: "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" aws_secret_access_key: '8rpb5q169RUtj7HU3njH3zxcKthZJmWbgtrzESXy'
associate_tag: "microv" associate_tag: 'microv'
solr_url: "http://tomcat:tomcat@localhost:8080/solr/venshop" solr_url: 'http://tomcat:tomcat@localhost:8080/solr/venshop'
default_perpage: 5 default_perpage: 5
default_send_mail: "no-reply@venshop.com" default_send_mail: 'no-reply@venshop.com'
...@@ -4,7 +4,7 @@ lock '3.1.0' ...@@ -4,7 +4,7 @@ lock '3.1.0'
require "whenever/capistrano" require "whenever/capistrano"
set :application, 'dieutb_venshop' set :application, 'dieutb_venshop'
set :branch, "dev" set :branch, "feature-refactor"
set :repo_url, 'git@gitlab.zigexn.vn:dieutb/VenShop.git' set :repo_url, 'git@gitlab.zigexn.vn:dieutb/VenShop.git'
set :whenever_command, "bundle exec whenever" set :whenever_command, "bundle exec whenever"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# Example: # Example:
# #
set :output, 'log/cron.log' set :output, 'log/cron.log'
set :environment, "production" set :environment, 'production'
every 1.hours do every 1.hours do
runner "CronjobService.new({klass: Product}).update(%w(price))" runner "CronjobService.new({klass: Product}).update(%w(price))"
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :role do
end
end
require 'rails_helper'
RSpec.describe Role, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment