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/plugins/acts_as_habtm_list -- Norman Timmler http://blog.inlet-media.de
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:> > 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/plugins/acts_as_habtm_list > > -- > Norman Timmler > > http://blog.inlet-media.de > > _______________________________________________ > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060222/abed5023/attachment.html
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
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/
> -----Original Message-----
> From: rails-bounces@lists.rubyonrails.org [mailto:rails-
> bounces@lists.rubyonrails.org] On Behalf Of Norman Timmler
> Sent: Wednesday, February 22, 2006 5:21 AM
> To: rails@lists.rubyonrails.org
> Subject: Re: [Rails] [ANN] acts_as_habtm_list plugin
>
> 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
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
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
Norman, Out of couriosity, how does this differ from act_as_nested_set? Thanks for Your Hard Work, Rob Kaufman On 2/22/06, Norman Timmler <lists@inlet-media.de> wrote:> 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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
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-- Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/.
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:
> 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.
>>
Kind regards,
Mats
----
"TextMate, coding with an incredible sense of joy and ease"
- www.macromates.com -