Skip to content

Commit

Permalink
Use new hash & lambda syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dlackty committed Feb 14, 2016
1 parent 42c2247 commit 25e311e
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 152 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def set_article

# Never trust parameters from the scary internet, only allow the white list through.
def article_params
params.require(:article).permit(:published, {:keyword_ids => []}, :description, :author,
params.require(:article).permit(:published, {keyword_ids: []}, :description, :author,
:published_at, :kind, :image, :image_cache, :remove_image, :title, :content, :youtube_url, :link)
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/catalogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sort
catalog_params[:order].each do |key,value|
Catalog.find(value[:id]).update_attribute(:position, value[:position])
end
render :nothing => true
render nothing: true
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sort
Category.find(value[:id]).update_attribute(:position, value[:position])
#Category.find(value[:id]).update_attribute(:catalog_id, value[:catalog_id])
end
render :nothing => true
render nothing: true
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/faqs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def sort
Faq.find(value[:id]).update_attribute(:position, value[:position])
end
end
render :nothing => true
render nothing: true
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/admin/keywords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ def sort
keyword_params[:order].each do |key,value|
Keyword.find(value[:id]).update_attribute(:position, value[:position])
end
render :nothing => true
render nothing: true
end

def show_sort
keyword_params[:order].each do |key,value|
Keyword.find(value[:id]).update_attribute(:show_position, value[:position])
end
render :nothing => true
render nothing: true
end

private
Expand All @@ -94,8 +94,8 @@ def set_keyword
# Never trust parameters from the scary internet, only allow the white list through.
def keyword_params
params.require(:keyword).permit(:category_id, :name, :published, :showed,
:image, :image_cache, :remove_image, :title, :content, :description,
:image, :image_cache, :remove_image, :title, :content, :description,
:cover, :cover_cache, :remove_cover, :position, {order: [:id, :position]},
:faqs_attributes => [:id, :question, :answer, :keyword_id, :_destroy])
faqs_attributes: [:id, :question, :answer, :keyword_id, :_destroy])
end
end
80 changes: 40 additions & 40 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def index
else
if user_signed_in? and current_user.admin?
@q = Article.includes(:keywords).search(params[:q])
@articles = @q.result(:distinct => true).page(params[:page])
@articles = @q.result(distinct: true).page(params[:page])
else
@q = Article.includes(:keywords).published.search(params[:q])
@articles = @q.result(:distinct => true).page(params[:page])
@articles = @q.result(distinct: true).page(params[:page])
end
end
set_meta_tags({
Expand All @@ -32,12 +32,12 @@ def index

respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -69,12 +69,12 @@ def presses
})
respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -106,12 +106,12 @@ def activities
})
respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.to_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.to_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -143,12 +143,12 @@ def comments
})
respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -180,12 +180,12 @@ def epapers
})
respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -217,12 +217,12 @@ def books
})
respond_to do |format|
format.html
format.json { render :json => {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
format.json { render json: {
status: "success",
articles: @articles.as_json(include: [:keywords], except: [:published]),
count: @articles_count
},
callback: params[:callback]
}
end
end
Expand Down Expand Up @@ -259,11 +259,11 @@ def show

respond_to do |format|
format.html
format.json { render :json => {
format.json { render json: {
status: "success",
article: @article.as_json(include: [:keywords], except: [:published]),
callback: params[:callback]
}
}
}
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/keywords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index
respond_to do |format|
format.html
format.json {
render :json => {
render json: {
status: "success",
keyword: @keywords,
count: count
Expand Down Expand Up @@ -70,15 +70,15 @@ def show
})
respond_to do |format|
format.html
format.json {render :json => {
format.json {render json: {
status: "success",
keyword: @keyword.as_json(
except: [:published, :created_at, :updated_at],
include: {
faqs: {},
articles: {except: [:published], include: [:keywords]}
})},
callback: params[:callback]
except: [:published, :created_at, :updated_at],
include: {
faqs: {},
articles: {except: [:published], include: [:keywords]}
})},
callback: params[:callback]
}
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
Expand All @@ -16,8 +16,8 @@ def facebook
def google_oauth2
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Google"
sign_in_and_redirect @user, event: :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
Expand Down
2 changes: 1 addition & 1 deletion app/models/ckeditor/asset.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Ckeditor::Asset < ActiveRecord::Base
include Ckeditor::Orm::ActiveRecord::AssetBase

delegate :url, :current_path, :content_type, :to => :data
delegate :url, :current_path, :content_type, to: :data

validates_presence_of :data
end
2 changes: 1 addition & 1 deletion app/models/ckeditor/attachment_file.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Ckeditor::AttachmentFile < Ckeditor::Asset
mount_uploader :data, CkeditorAttachmentFileUploader, :mount_on => :data_file_name
mount_uploader :data, CkeditorAttachmentFileUploader, mount_on: :data_file_name

def url_thumb
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
Expand Down
2 changes: 1 addition & 1 deletion app/models/ckeditor/picture.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Ckeditor::Picture < Ckeditor::Asset
mount_uploader :data, CkeditorPictureUploader, :mount_on => :data_file_name
mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name

def url_content
url(:content)
Expand Down
4 changes: 2 additions & 2 deletions app/models/keyword.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Keyword < ActiveRecord::Base
belongs_to :category
has_many :faqs, :dependent => :destroy
accepts_nested_attributes_for :faqs, :reject_if => :all_blank, :allow_destroy => true
has_many :faqs, dependent: :destroy
accepts_nested_attributes_for :faqs, reject_if: :all_blank, allow_destroy: true
has_and_belongs_to_many :articles, -> { uniq }
has_and_belongs_to_many :magazine_articles, -> { uniq }
validates_presence_of :name, message: '請填專案字名稱'
Expand Down
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook, :google_oauth2]
:omniauthable, omniauth_providers: [:facebook, :google_oauth2]
has_many :articles

def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :provider_uid => auth.uid).first
user = User.where(provider: auth.provider, provider_uid: auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
registered_user = User.where(email: auth.info.email).first
if registered_user
registered_user.provider = auth.provider
registered_user.provider_uid = auth.uid
Expand All @@ -30,11 +30,11 @@ def self.find_for_facebook_oauth(auth, signed_in_resource=nil)

def self.find_for_google_oauth2(auth, signed_in_resource=nil)
data = auth.info
user = User.where(:provider => auth.provider, :provider_uid => auth.uid ).first
user = User.where(provider: auth.provider, provider_uid: auth.uid ).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
registered_user = User.where(email: auth.info.email).first
if registered_user
registered_user.provider = auth.provider
registered_user.provider_uid = auth.uid
Expand Down
4 changes: 2 additions & 2 deletions app/uploaders/ckeditor_picture_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def store_dir

# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [118, 100]
process resize_to_fill: [118, 100]
end

version :content do
process :resize_to_limit => [800, 800]
process resize_to_limit: [800, 800]
end

# Add a white list of extensions which are allowed to be uploaded.
Expand Down
8 changes: 3 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@
config.active_record.dump_schema_after_migration = false
config.logger = Logger.new(config.paths["log"].first, 'weekly')
config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
options = event.payload.slice(:request_id, :user_id, :ip)
options[:params] = event.payload[:params].except("controller", "action")
options
end
config.lograge.custom_options = ->(event) { options = event.payload.slice(:request_id, :user_id, :ip)
options[:params] = event.payload[:params].except("controller", "action")
options }
end
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@

require "omniauth-facebook"
require "omniauth-google-oauth2"
config.omniauth :facebook, Setting.facebook_auth_key.app_id, Setting.facebook_auth_key.app_secret, :scope => 'email,user_likes,public_profile'
config.omniauth :google_oauth2, Setting.google_auth_key.client_id, Setting.google_auth_key.client_secret, { access_type: "offline", approval_prompt: "", :scope => 'email,profile' }
config.omniauth :facebook, Setting.facebook_auth_key.app_id, Setting.facebook_auth_key.app_secret, scope: 'email,user_likes,public_profile'
config.omniauth :google_oauth2, Setting.google_auth_key.client_id, Setting.google_auth_key.client_secret, { access_type: "offline", approval_prompt: "", scope: 'email,profile' }

# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
Expand Down
14 changes: 7 additions & 7 deletions config/initializers/swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ def self.transform_path(path, api_version)
Swagger::Docs::Config.register_apis({
"1.0" => {
# the extension used for the API
:api_extension_type => :json,
api_extension_type: :json,
# :controller_base_path => 'api',
# the output location where your .json files are written to
:api_file_path => "public/apidocs",
api_file_path: "public/apidocs",
# the URL base path to your API
:base_path => "#{Setting.url.protocol}://#{Setting.url.host}/",
base_path: "#{Setting.url.protocol}://#{Setting.url.host}/",
# if you want to delete all .json files at each generation
:clean_directory => true,
clean_directory: true,
# add custom attributes to api-docs
:attributes => {
:info => {
attributes: {
info: {
"title" => "民間司改會",
"description" => "民間司改會官方網站",
"contact" => "[email protected]",
"license" => "MIT"
}
}
}
})
})
Loading

0 comments on commit 25e311e

Please sign in to comment.