Forum: Ruby on Rails [ANN] acts_as_habtm_list plugin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-02-22 12:24
(Received via mailing list)
I'd like to announce acts_as_habtm_list plugin for rails.

acts_as_habtm_list is a Ruby on Rails plugin, that can manage ordered
lists through a join-table. It is providing almost the same Api as
acts_as_list. The position column has to be defined in the join table.

You can find additional information at:

http://www.inlet-media.de/acts_as_habtm_list/

Install it executing this command in your rails-application root
directory:

script/plugin install \
http://svn.inlet-media.de/svn/rails_extensions/plu...

--
Norman Timmler

http://blog.inlet-media.de
29b15f133c26b6dac0e4954d61733db9?d=identicon&s=25 Larry Kelly (Guest)
on 2006-02-22 14:16
(Received via mailing list)
Cool!

Does this work on Rails 1.0.0? or is edge rails necessary?
-Larry

On 2/22/06, Norman Timmler <lists@inlet-media.de> wrote:
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
Best Regards,
-Larry
"Work, work, work...there is no satisfactory alternative."
            --- E.Taft Benson
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-02-22 14:23
(Received via mailing list)
Am Mittwoch, den 22.02.2006, 05:14 -0800 schrieb Larry Kelly:

> Does this work on Rails 1.0.0? or is edge rails necessary?

No Edge Rails necessary! It works on Rails 1.0.0

--
Norman Timmler

http://blog.inlet-media.de
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-02-22 17:45
(Received via mailing list)
Looks like you still have some domain-specific code in it...

def scope_condition
  "#{configuration[:scope_foreign_key]} = \#{category_id}"
end

Note the category_id reference.


Bob Silva
http://www.railtie.net/
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-02-22 18:04
(Received via mailing list)
Am Mittwoch, den 22.02.2006, 08:43 -0800 schrieb Bob Silva:
> Looks like you still have some domain-specific code in it...

Thank you, Bob! I fixed it.

--
Norman Timmler

http://blog.inlet-media.de
2a3be1d8227283eb4e1613ef631d78b8?d=identicon&s=25 Rob Kaufman (Guest)
on 2006-02-22 19:39
(Received via mailing list)
Norman,
  Out of couriosity, how does this differ from act_as_nested_set?
Thanks for Your Hard Work,
Rob Kaufman
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-02-22 22:17
(Received via mailing list)
Am Mittwoch, den 22.02.2006, 10:38 -0800 schrieb Rob Kaufman:
>   Out of couriosity, how does this differ from act_as_nested_set?

A child can have multiple parents. All children under a specific parent
have a sort order. The same children under another parent may have a
different order.

--
Norman Timmler

http://blog.inlet-media.de
3cb5aadfd1626e37759e987c7184e372?d=identicon&s=25 Brendon Muir (spike)
on 2006-07-14 06:58
I'm having real difficulty understanding how to use this plugin.

I have the following:

Artist has many artworks and categories
Categories and artworks have one artist

Categories have many artworks
Artworks belong to many categories
(a habtm relationship?)

The big deal here is that I want artworks to be ordered within their
specific categories though they may belong to many. (this is what your
plugin does) however, I can't find any documentation that tells me how
to create that relationship to begin with. The user can make a bunch of
artworks, and make a bunch of categories. Then they can open a view that
shows the category box on the left and the list of available artworks on
the right and they can then drag and drop the artworks backward and
forward between the lists, and sort them within the categories list.

How exactly do I do this? as the moment I drop an artwork onto the
category it's going to send the array of artworks in the category back
to the controller which then needs to run through them and update their
position in the join table somehow.

I'm a bit of a n00b and the lack of documentation has caught me off
guard here :)

Cheers,

Brendon Muir

Norman Timmler wrote:
> Am Mittwoch, den 22.02.2006, 10:38 -0800 schrieb Rob Kaufman:
>>   Out of couriosity, how does this differ from act_as_nested_set?
>
> A child can have multiple parents. All children under a specific parent
> have a sort order. The same children under another parent may have a
> different order.
>
> --
> Norman Timmler
>
> http://blog.inlet-media.de
3cb5aadfd1626e37759e987c7184e372?d=identicon&s=25 Brendon Muir (spike)
on 2006-07-14 07:04
In addition, I currently have this as my controller code that gets
triggered when the drop takes place (it's probably way off and doesn't
seem to do anything or trigger errors at the moment).

  def order
    params[:categoryartworks].each_with_index { |id,idx|
Category.find(params[:category]).artworks.find(id).insert_at(:position
=> idx) }
    @category = Category.find(params[:category])
    render :partial => "move_artwork"
  end

Cheers,

Brendon

Brendon Muir wrote:
> I'm having real difficulty understanding how to use this plugin.
>
> I have the following:
>
> Artist has many artworks and categories
> Categories and artworks have one artist
>
> Categories have many artworks
> Artworks belong to many categories
> (a habtm relationship?)
>
> The big deal here is that I want artworks to be ordered within their
> specific categories though they may belong to many. (this is what your
> plugin does) however, I can't find any documentation that tells me how
> to create that relationship to begin with. The user can make a bunch of
> artworks, and make a bunch of categories. Then they can open a view that
> shows the category box on the left and the list of available artworks on
> the right and they can then drag and drop the artworks backward and
> forward between the lists, and sort them within the categories list.
>
> How exactly do I do this? as the moment I drop an artwork onto the
> category it's going to send the array of artworks in the category back
> to the controller which then needs to run through them and update their
> position in the join table somehow.
>
> I'm a bit of a n00b and the lack of documentation has caught me off
> guard here :)
>
> Cheers,
>
> Brendon Muir
>
> Norman Timmler wrote:
>> Am Mittwoch, den 22.02.2006, 10:38 -0800 schrieb Rob Kaufman:
>>>   Out of couriosity, how does this differ from act_as_nested_set?
>>
>> A child can have multiple parents. All children under a specific parent
>> have a sort order. The same children under another parent may have a
>> different order.
>>
>> --
>> Norman Timmler
>>
>> http://blog.inlet-media.de
855ddc9e30065b4061b08a7bd349a0af?d=identicon&s=25 Mats Persson (Guest)
on 2006-07-15 14:50
(Received via mailing list)
Brendon,

I too have been struggling with this issue over the past week, and
this is the solution I found and so far it works great (== much
better) for me.

Translated into what I think you want/need

class Category < ActiveRecord::Base
   has_many  :artworks,
             :through => :artwork_categories
   # get rid of all artwork categories when we delete a category
   has_many  :artwork_categories,
             :dependent => true,
             :order => :position
end
class Artwork < ActiveRecord::Base
   belongs_to :artist
   has_many :categories, :through => :artwork_categories
   # OK, make sure to get rid of any artwork_category entry
   # when we delete an artwork
   has_many :artwork_categories, :dependent => true
end
class ArtworkCategory < ActiveRecord::Base
   belongs_to :category
   belongs_to :artwork
   acts_as_list :scope  => :category_id
end
class Artist < ActiveRecord::Base
   has_many :artworks
end

# db.structure

create_table :category do |t|
   t.column :name, :string
end
create_table :artwork do |t|
   t.column :artist_id, :integer
   t.column :desc, :text
end
create_table :artwork_categories do |t|
   t.column :artwork_id, :integer
   t.column :category_id, :integer
   t.column :position, :integer
end
create_table :artist do |t|
   t.column :name, :string
end


The above should hopefully work as you want, if not all the way, then
at least some of the way. ;-)  Also read through all the posts at
blog.hasmanythrough.com they are a goldmine !!

Another really good thing to work with as a n00b, is Zentest
[ http://nubyonrails.com/articles/2006/04/19/autotest-rails] for all
the info. It's a really good thing to use when you're trying to learn
how to do things ;-)

Hope that got you moving forward, apologies for the rushed nature of
this post, but short of time right now.


On 14 Jul 2006, at 05:58, Brendon Muir wrote:

>
> How exactly do I do this? as the moment I drop an artwork onto the
>
> Norman Timmler wrote:
>> Am Mittwoch, den 22.02.2006, 10:38 -0800 schrieb Rob Kaufman:
>>>   Out of couriosity, how does this differ from act_as_nested_set?
>>
>> A child can have multiple parents. All children under a specific
>> parent
>> have a sort order. The same children under another parent may have a
>> different order.
>>


Kind regards,

Mats

----
"TextMate, coding with an incredible sense of joy and ease"
- www.macromates.com -
This topic is locked and can not be replied to.