active_scaffold 3.4.17 → 3.4.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -1
- data/README.md +8 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
- data/app/assets/stylesheets/active_scaffold.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/blue-theme.css +1 -1
- data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/lib/active_scaffold.rb +16 -16
- data/lib/active_scaffold/actions/common_search.rb +13 -11
- data/lib/active_scaffold/actions/core.rb +85 -78
- data/lib/active_scaffold/actions/create.rb +29 -28
- data/lib/active_scaffold/actions/delete.rb +17 -17
- data/lib/active_scaffold/actions/field_search.rb +18 -19
- data/lib/active_scaffold/actions/list.rb +30 -22
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +78 -65
- data/lib/active_scaffold/actions/search.rb +13 -10
- data/lib/active_scaffold/actions/show.rb +10 -6
- data/lib/active_scaffold/actions/subform.rb +1 -2
- data/lib/active_scaffold/actions/update.rb +39 -31
- data/lib/active_scaffold/active_record_permissions.rb +14 -15
- data/lib/active_scaffold/attribute_params.rb +42 -43
- data/lib/active_scaffold/bridges.rb +22 -12
- data/lib/active_scaffold/bridges/ancestry.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
- data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
- data/lib/active_scaffold/bridges/cancan.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
- data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
- data/lib/active_scaffold/bridges/chosen.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
- data/lib/active_scaffold/bridges/country_helper.rb +1 -1
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
- data/lib/active_scaffold/bridges/date_picker.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
- data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
- data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/file_column.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
- data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
- data/lib/active_scaffold/bridges/paperclip.rb +5 -5
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
- data/lib/active_scaffold/bridges/record_select.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
- data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
- data/lib/active_scaffold/config/base.rb +9 -10
- data/lib/active_scaffold/config/core.rb +24 -29
- data/lib/active_scaffold/config/create.rb +0 -1
- data/lib/active_scaffold/config/field_search.rb +8 -10
- data/lib/active_scaffold/config/form.rb +5 -5
- data/lib/active_scaffold/config/list.rb +21 -20
- data/lib/active_scaffold/config/mark.rb +3 -3
- data/lib/active_scaffold/config/nested.rb +11 -10
- data/lib/active_scaffold/config/search.rb +2 -3
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -2
- data/lib/active_scaffold/configurable.rb +9 -11
- data/lib/active_scaffold/constraints.rb +9 -8
- data/lib/active_scaffold/core.rb +72 -84
- data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
- data/lib/active_scaffold/data_structures/action_link.rb +43 -43
- data/lib/active_scaffold/data_structures/action_links.rb +17 -15
- data/lib/active_scaffold/data_structures/actions.rb +5 -5
- data/lib/active_scaffold/data_structures/bridge.rb +6 -3
- data/lib/active_scaffold/data_structures/column.rb +110 -89
- data/lib/active_scaffold/data_structures/columns.rb +3 -3
- data/lib/active_scaffold/data_structures/error_message.rb +4 -6
- data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
- data/lib/active_scaffold/data_structures/set.rb +7 -8
- data/lib/active_scaffold/data_structures/sorting.rb +38 -33
- data/lib/active_scaffold/delayed_setup.rb +5 -6
- data/lib/active_scaffold/engine.rb +4 -4
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
- data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
- data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
- data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
- data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
- data/lib/active_scaffold/finder.rb +90 -93
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
- data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
- data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
- data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
- data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
- data/lib/active_scaffold/marked_model.rb +10 -10
- data/lib/active_scaffold/paginator.rb +30 -34
- data/lib/active_scaffold/responds_to_parent.rb +27 -28
- data/lib/active_scaffold/tableless.rb +20 -15
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
- data/shoulda_macros/macros.rb +27 -22
- data/test/bridges/bridge_test.rb +38 -29
- data/test/bridges/date_picker_test.rb +1 -1
- data/test/bridges/paper_trail_test.rb +17 -0
- data/test/bridges/paperclip_test.rb +3 -2
- data/test/bridges/tiny_mce_test.rb +5 -2
- data/test/company.rb +25 -30
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +9 -9
- data/test/config/create_test.rb +14 -8
- data/test/config/delete_test.rb +4 -4
- data/test/config/field_search_test.rb +6 -6
- data/test/config/list_test.rb +16 -16
- data/test/config/nested_test.rb +4 -4
- data/test/config/search_test.rb +8 -8
- data/test/config/show_test.rb +6 -6
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +5 -5
- data/test/const_mocker.rb +4 -4
- data/test/data_structures/action_columns_test.rb +4 -5
- data/test/data_structures/action_link_test.rb +1 -0
- data/test/data_structures/action_links_test.rb +5 -5
- data/test/data_structures/column_test.rb +9 -9
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/error_message_test.rb +4 -5
- data/test/data_structures/set_test.rb +1 -2
- data/test/data_structures/sorting_test.rb +10 -10
- data/test/data_structures/validation_reflection_test.rb +8 -0
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -2
- data/test/helpers/pagination_helpers_test.rb +5 -4
- data/test/helpers/search_column_helpers_test.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +63 -50
- data/test/misc/attribute_params_test.rb +28 -26
- data/test/misc/calculation_test.rb +10 -3
- data/test/misc/configurable_test.rb +12 -13
- data/test/misc/constraints_test.rb +6 -6
- data/test/misc/convert_numbers_format_test.rb +7 -6
- data/test/misc/finder_test.rb +17 -12
- data/test/misc/lang_test.rb +3 -4
- data/test/misc/tableless_test.rb +2 -3
- data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
- data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
- data/test/mock_app/app/controllers/cars_controller.rb +1 -1
- data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
- data/test/mock_app/app/controllers/people_controller.rb +1 -1
- data/test/mock_app/app/models/file_model.rb +2 -2
- data/test/mock_app/app/models/person.rb +1 -1
- data/test/mock_app/config/application.rb +3 -3
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +1 -0
- data/test/mock_app/config/environments/development.rb +0 -1
- data/test/mock_app/config/environments/production.rb +1 -1
- data/test/mock_app/db/schema.rb +14 -15
- data/test/model_stub.rb +13 -16
- data/test/run_all.rb +5 -7
- data/test/test_helper.rb +12 -9
- metadata +19 -3
@@ -1,41 +1,41 @@
|
|
1
1
|
module ActiveScaffold
|
2
2
|
module MarkedModel
|
3
3
|
# This is a module aimed at making the make session_stored marked_records available to ActiveRecord models
|
4
|
-
|
4
|
+
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
7
|
extend ClassMethods
|
8
|
-
scope :as_marked,
|
8
|
+
scope :as_marked, -> { where(primary_key => marked_record_ids) }
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def as_marked
|
13
|
-
marked_records.include?(
|
13
|
+
marked_records.include?(id.to_s)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def as_marked=(value)
|
17
17
|
value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value)
|
18
18
|
if value == true
|
19
|
-
marked_records[
|
19
|
+
marked_records[id.to_s] = true unless as_marked
|
20
20
|
else
|
21
|
-
marked_records.delete(
|
21
|
+
marked_records.delete(id.to_s)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
module ClassMethods
|
26
26
|
def marked_records
|
27
27
|
Thread.current[:marked_records] ||= {}
|
28
28
|
end
|
29
29
|
|
30
30
|
def marked_records=(marked)
|
31
|
-
Thread.current[:marked_records] = marked
|
31
|
+
Thread.current[:marked_records] = marked
|
32
32
|
end
|
33
33
|
|
34
34
|
def marked_record_ids
|
35
35
|
marked_records.keys
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# Instance-level access to the marked_records
|
40
40
|
def marked_records
|
41
41
|
self.class.marked_records
|
@@ -1,123 +1,121 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
class Paginator
|
4
|
-
|
5
4
|
VERSION = '1.0.9'
|
6
5
|
|
7
6
|
class ArgumentError < ::ArgumentError; end
|
8
7
|
class MissingCountError < ArgumentError; end
|
9
|
-
class MissingSelectError < ArgumentError; end
|
10
|
-
|
11
|
-
attr_reader :per_page, :count
|
12
|
-
|
8
|
+
class MissingSelectError < ArgumentError; end
|
9
|
+
|
10
|
+
attr_reader :per_page, :count
|
11
|
+
|
13
12
|
# Instantiate a new Paginator object
|
14
13
|
#
|
15
14
|
# Provide:
|
16
15
|
# * A total count of the number of objects to paginate
|
17
16
|
# * The number of objects in each page
|
18
17
|
# * A block that returns the array of items
|
19
|
-
# * The block is passed the item offset
|
18
|
+
# * The block is passed the item offset
|
20
19
|
# (and the number of items to show per page, for
|
21
20
|
# convenience, if the arity is 2)
|
22
21
|
def initialize(count, per_page, &select)
|
23
22
|
@count, @per_page = count, per_page
|
24
23
|
unless select
|
25
|
-
raise MissingSelectError,
|
24
|
+
raise MissingSelectError, 'Must provide block to select data for each page'
|
26
25
|
end
|
27
26
|
@select = select
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
# Total number of pages
|
31
30
|
def number_of_pages
|
32
|
-
|
31
|
+
(@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0)
|
33
32
|
end
|
34
|
-
|
33
|
+
|
35
34
|
# First page object
|
36
35
|
def first
|
37
36
|
page 1
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
# Last page object
|
41
40
|
def last
|
42
41
|
page number_of_pages
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
# Iterate through pages
|
46
45
|
def each
|
47
|
-
each_with_index do |item,
|
46
|
+
each_with_index do |item, _|
|
48
47
|
yield item
|
49
48
|
end
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
# Iterate through pages with indices
|
53
52
|
def each_with_index
|
54
53
|
1.upto(number_of_pages) do |number|
|
55
54
|
yield(page(number), number - 1)
|
56
55
|
end
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
# Retrieve page object by number
|
60
59
|
def page(number)
|
61
60
|
number = (n = number.to_i) > 0 ? n : 1
|
62
|
-
Page.new(self, number
|
61
|
+
Page.new(self, number) do
|
63
62
|
offset = (number - 1) * @per_page
|
64
63
|
args = [offset]
|
65
64
|
args << @per_page if @select.arity == 2
|
66
65
|
@select.call(*args)
|
67
|
-
|
66
|
+
end
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
# Page object
|
71
70
|
#
|
72
71
|
# Retrieves items for a page and provides metadata about the position
|
73
72
|
# of the page in the paginator
|
74
73
|
class Page
|
75
|
-
|
76
74
|
extend Forwardable
|
77
75
|
def_delegator :@pager, :first, :first
|
78
76
|
def_delegator :@pager, :last, :last
|
79
77
|
def_delegator :items, :each
|
80
|
-
def_delegator :items, :each_with_index
|
81
|
-
|
78
|
+
def_delegator :items, :each_with_index
|
79
|
+
|
82
80
|
attr_reader :number, :pager
|
83
|
-
|
84
|
-
def initialize(pager, number, select) #:nodoc:
|
81
|
+
|
82
|
+
def initialize(pager, number, &select) #:nodoc:
|
85
83
|
@pager, @number = pager, number
|
86
84
|
@offset = (number - 1) * pager.per_page
|
87
85
|
@select = select
|
88
86
|
end
|
89
|
-
|
87
|
+
|
90
88
|
# Retrieve the items for this page
|
91
89
|
# * Caches
|
92
90
|
def items
|
93
91
|
@items ||= @select.call
|
94
92
|
end
|
95
|
-
|
93
|
+
|
96
94
|
# Checks to see if there's a page before this one
|
97
95
|
def prev?
|
98
96
|
@number > 1
|
99
97
|
end
|
100
|
-
|
98
|
+
|
101
99
|
# Get previous page (if possible)
|
102
100
|
def prev
|
103
101
|
@pager.page(@number - 1) if prev?
|
104
102
|
end
|
105
|
-
|
103
|
+
|
106
104
|
# Checks to see if there's a page after this one
|
107
105
|
def next?
|
108
106
|
@number < @pager.number_of_pages
|
109
107
|
end
|
110
|
-
|
108
|
+
|
111
109
|
# Get next page (if possible)
|
112
110
|
def next
|
113
111
|
@pager.page(@number + 1) if next?
|
114
112
|
end
|
115
|
-
|
113
|
+
|
116
114
|
# The "item number" of the first item on this page
|
117
115
|
def first_item_number
|
118
116
|
1 + @offset
|
119
117
|
end
|
120
|
-
|
118
|
+
|
121
119
|
# The "item number" of the last item on this page
|
122
120
|
def last_item_number
|
123
121
|
if next?
|
@@ -126,11 +124,9 @@ class Paginator
|
|
126
124
|
@pager.count
|
127
125
|
end
|
128
126
|
end
|
129
|
-
|
127
|
+
|
130
128
|
def ==(other) #:nodoc:
|
131
|
-
@pager == other.pager &&
|
129
|
+
@pager == other.pager && number == other.number
|
132
130
|
end
|
133
|
-
|
134
131
|
end
|
135
|
-
|
136
132
|
end
|
@@ -6,39 +6,38 @@ module ActiveScaffold
|
|
6
6
|
# to use IFRAME base RPC.
|
7
7
|
def responds_to_parent(&block)
|
8
8
|
yield
|
9
|
+
return unless performed?
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
11
|
+
# Either pull out a redirect or the request body
|
12
|
+
script = if response.headers['Location']
|
13
|
+
"document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
|
14
|
+
else
|
15
|
+
response.body || ''
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
# Eval in parent scope and replace document location of this frame
|
19
|
+
# so back button doesn't replay action on targeted forms
|
20
|
+
# loc = document.location to be set after parent is updated for IE
|
21
|
+
# with(window.parent) - pull in variables from parent window
|
22
|
+
# setTimeout - scope the execution in the windows parent for safari
|
23
|
+
# window.eval - legal eval for Opera
|
24
|
+
script = "<html><body><script type='text/javascript' charset='utf-8'>
|
25
|
+
var loc = document.location;
|
26
|
+
with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
|
27
|
+
</script></body></html>"
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
# We're returning HTML instead of JS or XML now
|
30
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
render :text => script
|
32
|
+
# Clear out the previous render to prevent double render and then render
|
33
|
+
if respond_to?(:erase_results, true)
|
34
|
+
erase_results
|
35
|
+
else
|
36
|
+
instance_variable_set(:@_response_body, nil)
|
40
37
|
end
|
38
|
+
|
39
|
+
render :text => script
|
41
40
|
end
|
42
|
-
|
41
|
+
alias_method :respond_to_parent, :responds_to_parent
|
43
42
|
end
|
44
43
|
end
|
@@ -16,7 +16,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
class Connection < ActiveRecord::ConnectionAdapters::AbstractAdapter
|
21
21
|
attr_reader :klass
|
22
22
|
def initialize(klass, *args)
|
@@ -44,7 +44,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
44
44
|
@association_scope ||= overrided_association_scope if klass < ActiveScaffold::Tableless
|
45
45
|
association_scope_without_tableless
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def overrided_association_scope
|
49
49
|
if AssociationScope.respond_to?(:scope) # rails >= 4.1
|
50
50
|
AssociationScope.scope(self, klass.connection)
|
@@ -61,7 +61,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
module CollectionAssociation
|
66
66
|
def self.included(base)
|
67
67
|
base.alias_method_chain :get_records, :tableless if Rails.version >= '4.2'
|
@@ -70,7 +70,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
70
70
|
klass < ActiveScaffold::Tableless ? scope.to_a : get_records_without_tableless
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
module SingularAssociation
|
75
75
|
def self.included(base)
|
76
76
|
base.alias_method_chain :get_records, :tableless if Rails.version >= '4.2'
|
@@ -81,10 +81,8 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
81
81
|
end
|
82
82
|
|
83
83
|
module RelationExtension
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
84
|
+
attr_reader :conditions
|
85
|
+
|
88
86
|
def initialize(klass, table)
|
89
87
|
super
|
90
88
|
@conditions ||= []
|
@@ -120,7 +118,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
120
118
|
end
|
121
119
|
|
122
120
|
def find_one(id)
|
123
|
-
@klass.find_one(id, self)
|
121
|
+
@klass.find_one(id, self) || raise(ActiveRecord::RecordNotFound)
|
124
122
|
end
|
125
123
|
|
126
124
|
def execute_simple_calculation(operation, column_name, distinct)
|
@@ -133,6 +131,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
133
131
|
end
|
134
132
|
class << self
|
135
133
|
private
|
134
|
+
|
136
135
|
def relation
|
137
136
|
ActiveScaffold::Tableless::Relation.new(self, arel_table)
|
138
137
|
end
|
@@ -151,7 +150,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
151
150
|
unless Rails.version < '4.2'
|
152
151
|
def self.columns_hash
|
153
152
|
if self < ActiveScaffold::Tableless
|
154
|
-
@columns_hash ||= Hash[
|
153
|
+
@columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
|
155
154
|
else
|
156
155
|
super
|
157
156
|
end
|
@@ -161,17 +160,23 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
161
160
|
end
|
162
161
|
end
|
163
162
|
|
164
|
-
def self.columns
|
165
|
-
|
166
|
-
|
163
|
+
def self.columns
|
164
|
+
@columns ||= []
|
165
|
+
end
|
166
|
+
def self.table_name
|
167
|
+
@table_name ||= ActiveModel::Naming.plural(self)
|
168
|
+
end
|
169
|
+
def self.table_exists?
|
170
|
+
true
|
171
|
+
end
|
167
172
|
self.abstract_class = true
|
168
|
-
|
173
|
+
|
169
174
|
def self.connection
|
170
175
|
@connection ||= Connection.new(self)
|
171
176
|
end
|
172
177
|
|
173
178
|
def self.column(name, sql_type = nil, options = {})
|
174
|
-
column = Column.new(name.to_s, options[:default], sql_type.to_s, options.
|
179
|
+
column = Column.new(name.to_s, options[:default], sql_type.to_s, options.key?(:null) ? options[:null] : true)
|
175
180
|
column.tap { columns << column }
|
176
181
|
end
|
177
182
|
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'rails/generators/rails/resource/resource_generator'
|
2
|
-
#require 'generators/active_scaffold_controller/active_scaffold_controller_generator'
|
2
|
+
# require 'generators/active_scaffold_controller/active_scaffold_controller_generator'
|
3
3
|
|
4
4
|
module Rails
|
5
5
|
module Generators
|
6
|
-
class ActiveScaffoldGenerator < ResourceGenerator #metagenerator
|
6
|
+
class ActiveScaffoldGenerator < ResourceGenerator # metagenerator
|
7
7
|
remove_hook_for :resource_controller
|
8
8
|
remove_hook_for :resource_route
|
9
9
|
remove_class_option :actions
|
10
|
-
|
10
|
+
|
11
11
|
def add_resource_route
|
12
|
-
route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(
|
12
|
+
route_config = class_path.collect { |namespace| "namespace :#{namespace} do " }.join(' ')
|
13
13
|
route_config << "resources :#{file_name.pluralize} do as_routes end"
|
14
|
-
route_config <<
|
14
|
+
route_config << ' end' * class_path.size
|
15
15
|
route route_config
|
16
|
-
end
|
17
|
-
|
18
|
-
invoke
|
16
|
+
end
|
17
|
+
|
18
|
+
invoke 'active_scaffold_controller'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
#require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
1
|
+
# require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module Generators
|
5
|
-
class ActiveScaffoldControllerGenerator < NamedBase #metagenerator
|
5
|
+
class ActiveScaffoldControllerGenerator < NamedBase # metagenerator
|
6
6
|
include ResourceHelpers
|
7
7
|
|
8
8
|
def self.source_root
|
9
|
-
|
9
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
10
10
|
end
|
11
11
|
|
12
|
-
check_class_collision :suffix =>
|
12
|
+
check_class_collision :suffix => 'Controller'
|
13
13
|
|
14
|
-
class_option :orm, :banner =>
|
15
|
-
:desc =>
|
14
|
+
class_option :orm, :banner => 'NAME', :type => :string, :required => true,
|
15
|
+
:desc => 'ORM to generate the controller for'
|
16
16
|
|
17
17
|
def create_controller_files
|
18
18
|
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
@@ -22,8 +22,8 @@ module Rails
|
|
22
22
|
hook_for :test_framework, :as => :scaffold
|
23
23
|
|
24
24
|
def create_view_root_folder
|
25
|
-
empty_directory File.join(
|
26
|
-
end
|
25
|
+
empty_directory File.join('app/views', controller_file_path)
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|