ActiveScaffoldSortable in 2.2?

6 views
Skip to first unread message

David C

unread,
Jan 30, 2009, 2:57:50 AM1/30/09
to ActiveScaffold : Ruby on Rails plugin
Has anyone gotten ActiveScaffoldSortable working with Rails 2.2? It's
README says it's not compatible with Rails 2.1, but I do have it
working in a Railsl 2.1 project (it dropped right in and I only had to
tweak the route definition), but it's not functional with Rails 2.2 --
it just seems to be silently ignored. No errors are generated and the
sortable column does not appear in the list actions.

Thought I'd check here first before diving into the code.

Kenny Ortmann

unread,
Jan 30, 2009, 10:04:28 AM1/30/09
to actives...@googlegroups.com
I believe the reasoning behind saying that the plugin is not yet compatible with Rails 2.1 is because it was compatible with Rails 2.0, therefore it has not been maintained.

If you get it working with Rails 2.2 let me know.

David Cato

unread,
Jan 30, 2009, 9:21:03 PM1/30/09
to Kenny Ortmann, actives...@googlegroups.com
Kenny Ortmann wrote ...

> I believe the reasoning behind saying that the plugin is not yet compatible
> with Rails 2.1 is because it was compatible with Rails 2.0, therefore it has
> not been maintained.
>
> If you get it working with Rails 2.2 let me know.

Turns out that the primary problem seems to be restricted to the view
path, and the following patch resolves it. Note that I didn't remove
the old code so that it will still work with Rails < 2.2.

diff --git a/lib/actions/sortable.rb b/lib/actions/sortable.rb
index 669a369..7ba6a61 100644
--- a/lib/actions/sortable.rb
+++ b/lib/actions/sortable.rb
@@ -15,6 +15,8 @@ module ActiveScaffold::Actions

if base.respond_to?(:generic_view_paths) && ! base.generic_view_paths.empty?
base.generic_view_paths.insert(0, sortable_plugin_path)
+ elsif base.respond_to?(:view_paths)
+ base.prepend_view_path(sortable_plugin_path)
else
config.inherited_view_paths << sortable_plugin_path
end

A secondary problem is with the RESTful route generation which is fixed
with the following patch. I don't know if it's a change from 2.0 or
something odd in my setup, but the original member route generation just
does not work and it doesn't make sense to me to reference
/controller/:id/reorder since you're reordering the whole collection.

diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb
index c33cd24..34c5390 100644
--- a/lib/extensions/resources.rb
+++ b/lib/extensions/resources.rb
@@ -5,8 +5,8 @@ module ActionController
def options_with_as_sortable
if @options.delete(:active_scaffold_sortable)
logger.info "active_scaffold_sortable: extending RESTful routes for #{@plural}"
- @options[:member] ||= {}
- @options[:member].merge!(:reorder => :post)
+ @options[:collection] ||= {}
+ @options[:collection].merge!(:reorder => :post)
end
options_without_as_sortable
end

After applying both patches, ActiveScaffoldSortable is working for me in
in both a 2.1 and a 2.2 environment (I have not tested edge or anything
earlier than 2.1).

Reply all
Reply to author
Forward
0 new messages