Skip to content
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

rails >= 3.2 instead of ~> 3.2 #5

Open
wants to merge 11 commits into
base: ruby2
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
2 changes: 1 addition & 1 deletion active_scaffold.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<rcov>, [">= 0"])
#s.add_runtime_dependency(%q<render_component_vho>, [">= 0"])
s.add_runtime_dependency(%q<rails>, "~> 3.2.0")
s.add_runtime_dependency(%q<rails>, ">= 3.2.0")
end

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%
parent_record = @record
associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a
associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order)
if show_blank_record = column.show_blank_record?(associated)
associated << build_associated(column, parent_record)
end
Expand Down
6 changes: 1 addition & 5 deletions lib/active_scaffold.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
raise "This version of ActiveScaffold requires Rails 3.1 or higher. Please use an earlier version."
end

begin
require 'render_component'
rescue LoadError
Expand Down Expand Up @@ -187,7 +183,7 @@ def active_scaffold(model_id = nil, &block)

# defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
klass = self.active_scaffold_config.model
klass.define_attribute_methods unless klass.attribute_methods_generated?
klass.define_attribute_methods # unless klass.attribute_methods_generated?
# include the rest of the code into the controller: the action core and the included actions
module_eval do
include ActiveScaffold::Finder
Expand Down
6 changes: 1 addition & 5 deletions lib/active_scaffold/actions/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ def authorized_for?(options = {})
end

def clear_flashes
if request.xhr?
flash.keys.each do |flash_key|
flash[flash_key] = nil
end
end
flash.clear if request.xhr?
end

def each_marked_record(&block)
Expand Down
18 changes: 13 additions & 5 deletions lib/active_scaffold/extensions/name_option_for_datetime.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
module ActionView
module Helpers
class InstanceTag
private
module ActiveScaffold
module Extensions
module NameOptionForDatetime
def self.included(base)
base.class_eval do
alias_method_chain :datetime_selector, :name
private :datetime_selector_without_name, :datetime_selector_with_name, :datetime_selector
end
end

def datetime_selector_with_name(options, html_options)
options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name]
datetime_selector_without_name(options, html_options)
end
alias_method_chain :datetime_selector, :name
end
end
end

# klass = defined?(ActionView::Helpers::InstanceTag) ? ActionView::Helpers::InstanceTag : ActionView::Helpers::Tags::DateSelect
ActionView::Helpers::Tags::DateSelect.include(ActiveScaffold::Extensions::NameOptionForDatetime)
10 changes: 5 additions & 5 deletions lib/active_scaffold/extensions/unsaved_associated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def associations_for_update
# returns false if any yield returns false.
# returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly.
def with_unsaved_associated
associations_for_update.all? do |association|
association_proxy = send(association.name)
if association_proxy
records = association_proxy
associations_for_update.map do |association|
association_proxy = self.association(association.name)
if association_proxy&.target&.present?
records = association_proxy.target
records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use
records.select {|r| r.unsaved? and not r.readonly?}.all? {|r| yield r} # must use select instead of find_all, which Rails overrides on association proxies for db access
else
true
end
end
end.all?
end
end
4 changes: 2 additions & 2 deletions lib/active_scaffold/helpers/association_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def association_options_find(association, conditions = nil, klass = nil)
relation = klass.where(conditions).where(association.options[:conditions])
relation = relation.includes(association.options[:include]) if association.options[:include]
relation = yield(relation) if block_given?
relation.all
relation.to_a
end

# Provides a way to honor the :conditions on an association while searching the association's klass
Expand All @@ -32,7 +32,7 @@ def association_options_count(association, conditions = nil)

# returns options for the given association as a collection of [id, label] pairs intended for the +options_for_select+ helper.
def options_for_association(association, include_all = false)
ActiveSupport::Deprecation.warn "options_for_association should not be used, use association_options_find directly"
# ActiveSupport::Deprecation.warn "options_for_association should not be used, use association_options_find directly"
available_records = association_options_find(association, include_all ? nil : options_for_association_conditions(association))
available_records ||= []
available_records.sort{|a,b| a.to_label <=> b.to_label}.collect { |model| [ model.to_label, model.id ] }
Expand Down