diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index cb472dcfed..85fb383ac4 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -25,6 +25,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, [">= 0"]) #s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, "~> 3.2.0") + s.add_runtime_dependency(%q, ">= 3.2.0") end diff --git a/app/views/active_scaffold_overrides/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb index ab48385f44..a551f3ae77 100644 --- a/app/views/active_scaffold_overrides/_form_association.html.erb +++ b/app/views/active_scaffold_overrides/_form_association.html.erb @@ -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 diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 19cba834f6..981bb4b946 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -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 @@ -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 diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fb3ff7dd47..331ad259f6 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -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) diff --git a/lib/active_scaffold/extensions/name_option_for_datetime.rb b/lib/active_scaffold/extensions/name_option_for_datetime.rb index 48c4580cd1..ddb264f9b7 100644 --- a/lib/active_scaffold/extensions/name_option_for_datetime.rb +++ b/lib/active_scaffold/extensions/name_option_for_datetime.rb @@ -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) diff --git a/lib/active_scaffold/extensions/unsaved_associated.rb b/lib/active_scaffold/extensions/unsaved_associated.rb index 2ae2523395..1307fee762 100644 --- a/lib/active_scaffold/extensions/unsaved_associated.rb +++ b/lib/active_scaffold/extensions/unsaved_associated.rb @@ -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 diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index d2e6c5d0e5..03d4a39606 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -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 @@ -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 ] }