Skip to content

changes for rails 5 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/approval2/controller_additions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module ControllerAdditions
extend ActiveSupport::Concern

included do
before_filter :before_edit, only: :edit
before_filter :before_approve, only: :approve
before_filter :before_index, only: :index
before_action :before_edit, only: :edit
before_action :before_approve, only: :approve
before_action :before_index, only: :index
end


Expand Down
11 changes: 4 additions & 7 deletions lib/approval2/model_additions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ module ModelAdditions
has_one :unapproved_record_entry, :as => :approvable, :class_name => '::UnapprovedRecord'

# refers to the approved/unapproved record in the model
belongs_to :unapproved_record, :primary_key => 'approved_id', :foreign_key => 'id', :class_name => self.name, :unscoped => true
belongs_to :approved_record, :foreign_key => 'approved_id', :primary_key => 'id', :class_name => self.name, :unscoped => true
belongs_to :unapproved_record, -> { unscope(where: :approval_status) }, :primary_key => 'approved_id', :foreign_key => 'id', :class_name => self.name
belongs_to :approved_record, -> { unscope(where: :approval_status) }, :foreign_key => 'approved_id', :primary_key => 'id', :class_name => self.name

validates_uniqueness_of :approved_id, :allow_blank => true
validate :validate_unapproved_record

def self.default_scope
where approval_status: 'A'
end

default_scope { where('approval_status = ?', 'A') }

after_create :on_create_create_unapproved_record_entry
after_destroy :on_destory_remove_unapproved_record_entries
Expand Down Expand Up @@ -70,7 +67,7 @@ def enable_approve_button?
self.approval_status == 'U' ? true : false
end

def on_create_create_unapproved_record_entry
def on_create_create_unapproved_record_entry
if approval_status == 'U'
UnapprovedRecord.create!(:approvable => self)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/approval2/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Approval2
VERSION = "0.1.6"
VERSION = "0.1.7"
end