Figured someone else may look for it in the future.
OK, say you have a model that you have "acts_as_list" defined. And
you want this list always in order and want to be able to move the
order up and down and move an item to the top or bottom of the list.
This is how you do it (quick unexplained version, I'll put the longer
version on my blog http://www.blognow.com.au/q/ soon)
In your controller put:
class ItemsController < ApplicationController
active_scaffold :items do |config|
config.action_links.add 'up', :label => 'Up', :type
=> :record, :position => false, :method => 'put'
config.action_links.add 'down', :label => 'Down', :type
=> :record, :position => false, :method => 'put'
config.action_links.add 'top', :label => 'Top', :type
=> :record, :position => false, :method => 'put'
config.action_links.add 'bottom', :label => 'Bottom', :type
=> :record, :position => false, :method => 'put'
end
def up
@item = Item.find(params[:id])
@item.move_higher
do_list
render :action => 'move'
end
def down
@item = Item.find(params[:id])
@item.move_lower
do_list
render :action => 'move'
end
def top
@item = Item.find(params[:id])
@item.move_to_top
do_list
render :action => 'move'
end
def bottom
@item = Item.find(params[:id])
@item.move_to_bottom
do_list
render :action => 'move'
end
def move
end
end
Then make one file in /app/views/items/, called "move.rjs" This
contains one line:
page.replace_html active_scaffold_content_id, :partial => "list"
Note, it has to be page.replace_html not page.replace otherwise your
return message gets rendered as escaped HTML, not pretty :)
That's it, now you have a sortable updating list with four buttons on
it (Up Down Top Bottom). Click a button and the position values
change for the whole list. if you have the position column visible
and clicked, it will also dynamically resort the list as well.
One thing I am not sure how to do (guidance would be nice) is how do I
set the column so it is ALWAYS sorted by position in ascending order
(ie, effectively has the position column always clicked). this is
persistent between updates if you click the position column once, but
not sure how to set it as default when you load the page.
These buttons are pretty trivial, maybe they could be bundled in to
show if you have an acts_as_list model. Voila, instant acts as list
support :)
Regards
Mikel
As far as default sorting, you want the config.list.sorting =
[:column, :other] property.
http://activescaffold.com/docs/api-list
Good to see if you can put it into a plugin :) Then I can see how you
did it too!
Oh.. and the config.list.sorting was exactly what I needed... can't
belived I didn't se eit before.
regards
Mikel
thanks
On Jun 20, 6:12 am, Daniel E <deinspan...@gmail.com> wrote:
> http://wiki.activescaffold.com/wiki/show/ActsAsListReorderingActionPl...http://groups.google.com/group/activescaffold/web/active_scaffold_act...
On Jul 24, 6:54 pm, "Lance Ivy" <la...@cainlevy.net> wrote:
> looks like someone spammed the wiki page, so i did a rollback.
>
> On 7/24/07, Differenthink <guillaume.mont...@gmail.com> wrote:
>
>
>
> > Hum it seems that the wiki page was removed :/... any idea why ?
> > i would like to have a doc about this plugin, i guess it was on that
> > wiki... it could help other people to get it back on ..
>
> > thanks
>
> > On Jun 20, 6:12 am, Daniel E <deinspan...@gmail.com> wrote:
>
> >http://wiki.activescaffold.com/wiki/show/ActsAsListReorderingActionPl....
http://wiki.activescaffold.com/wiki/show/ActsAsListReorderingActionPlugin
Regards
Mikel
====================================================
Exiting
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
core_ext/module/aliasing.rb:28:in `alias_method': undefined method
`active_scaffold_includes' for module
`ActiveScaffold::Helpers::ViewHelpers' (NameError)
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/core_ext/module/aliasing.rb:28:in `alias_method_chain'
from script/../config/../vendor/plugins/
active_scaffold_acts_as_list/lib/helpers/view_helpers.rb:10
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:342:in `new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
from script/../config/../vendor/plugins/
active_scaffold_acts_as_list/init.rb:8:in `load_plugin'
from /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
initializer.rb:401:in `load_plugin'
... 35 levels...
from /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/
server.rb:39
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
from ./script/server:3
===============================================================================
I believe that the two following lines cause the problem?
alias_method_chain :active_scaffold_includes, :aal
alias_method_chain :render_action_link, :aal
If I comment them out the webbrick server starts, but then the plugin
doesn't work.
Thanks
I have exported the trunk version, and renamed the 1.0.1
active_scaffold to bk_active_scaffold, but I'm getting a different
error now.
=============================================
NoMethodError (undefined method `exclude' for
#<ActiveScaffold::DataStructures::Columns:0xb693fe20>):
.//vendor/plugins/active_scaffold/lib/configurable.rb:19:in
`method_missing'
.//vendor/plugins/active_scaffold/lib/config/core.rb:96:in
`initialize'
.//vendor/plugins/active_scaffold/lib/active_scaffold.rb:47:in
`new'
=========================================
!! Didn't know about it, but I've discovered it when most things were
not working :-(....
Now I know..
Won't do it again :-)
On Jul 25, 5:09 pm, "Lance Ivy" <la...@cainlevy.net> wrote:
> It's kinda dangerous to have two versions of ActiveScaffold in your
> /vendor/plugins directory. They're both going to get loaded no matter what
> you name them.
>
Now that I know I'll do that whenever it happens again.
Cheers..
I've been reading the old messages from this group to help me get
started. I finally got active_scaffold running from the trunk release.
I chose the trunk release because I want to use
active_scaffold_acts_as_list.
But I'm finding that with the plugin for active_scaffold_acts_as_list,
I get always an error message if my class acts_as_list.
For example I have a bottle class, it's very simple...
class Bottle < ActiveRecord::Base
acts_as_list
end
and when I try to view the bottles this is the error I get.
DBI::DatabaseError: Execute
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL
Server
Incorrect syntax near '\.'.
HRESULT error code:0x80020009
Exception occurred.: SELECT * FROM (SELECT TOP 15 * FROM (SELECT
TOP 15 * FROM bottles ORDER BY bottles.[position] ASC) AS tmp1 ORDER
BY bottles\.\[[position]\] DESC) AS tmp2 ORDER BY bottles\.\[[position]
\] ASC
I don't get this error message when I remove the plugin -- so I was
wondering if maybe there is some sort of bug in the
active_scaffold_acts_as_list plugin?
I am running mongrel rails on windows, and connecting to MS SQLServer
(sorry). The ado.rb file in root:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/
ADO.rb is up to date.
Thanks in advance for any tips on how I can get this working.
:)
The latest version of the active_scaffold plugin works... but the
latest version doesn't work with active_scaffold_acts_as_list. :(
That's about all I know, I wish I could fix it!
Daniel
On Aug 4, 2:39 am, "Lance Ivy" <la...@cainlevy.net> wrote:
> Have you tried the patched SQL Server adapter? Seehttp://groups.google.com/group/activescaffold/files/.
>