Acts_as_list with has_and_belongs_to_many

Hi,
I found the problem below on the Rails wiki and have the very same
problem.
Can anyone suggest a solution that does not involve an extra object like
on
the wiki?
Thanks,
Peter
From: Peak Obsession
I’m looking for a Howto that would explain how to use
ActsAsListhttp://wiki.rubyonrails.com/rails/pages/ActsAsListwhere
you have something like the following:

Book

  • id
  • name

Category

  • id
  • name

books_categories

  • book_id
  • category_id
  • position

The position in the books_categories table is relative to the category.
Thus, under one category book A might be in position 4, while in another
category it might be in position 1.

Ok, I’ve searched everywhere trying to figure this one out… Mechanize
(installed from gems) is trying to reference a function that it can’t
find.

I’m using:

  • Mechanize (install gem mechanize)
  • the newest Ruby / Rails versions.

I’m getting this error:
undefined method `add_header’ for #<Net::HTTP::Post POST>

I know that mechanize is doing something with some files from Ruby 1.9
and
has a file that says this:

required due to the missing get_fields method in Ruby 1.8.2

$LOAD_PATH.unshift File.join(File.dirname(FILE), “mechanize”,
“net-overrides”)
and that it has this file:

/usr/local/lib/ruby/gems/1.8/gems/mechanize-0.3.1/lib/mechanize/net-override
s/net/http.rb

So, for some reason it would appear that mechanize can’t see the
over-ridden
function???

It had the same problem with the “get_fields” function (which is in the
same
place, and is a thing the mechanize developer added since Ruby 1.8
doesn’t
have the response.get_fields function), but I got around that by adding
a
function:
def get_fields2(response,key)
return nil unless response.header[key.downcase]
response.header[key.downcase].dup
end
to /usr/local/lib/ruby/gems/1.8/gems/mechanize-0.3.1/lib/mechanize.rb
and
then changing the references to “response.get_fields(…)” to
“get_fields2(response,…)” … But that approach doesn’t work for the
add_header function.

Thanks for any help!
-Greg

Greg E.
Chief Technical Officer
Eyetools, Inc.
(916) 792-4538
[email protected]
http://www.eyetools.com

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Peter M.
Sent: Friday, November 18, 2005 1:10 PM
To: [email protected]
Subject: [Rails] acts_as_list with has_and_belongs_to_many

Hi,

I found the problem below on the Rails wiki and have the very same
problem. Can anyone suggest a solution that does not involve an extra
object
like on the wiki?

Thanks,
Peter

From: Peak Obsession

I’m looking for a Howto that would explain how to use ActsAsList where
you
have something like the following:
Book

  • id
  • name

Category

  • id
  • name

books_categories

  • book_id
  • category_id
  • position
    The position in the books_categories table is relative to the category.
    Thus, under one category book A might be in position 4, while in another
    category it might be in position 1.

Reading the Rails source for acts_as_list and the ActiveRecord base.rb,
part
of the problem seems to be that acts_as_list doesn’t now about model
associations. Also it appears that sql update statements made with rails
update_all cannot have multiple tables. Is all of this true?

Couldn’t we have something like the following with the conventional join
table being included automatically?

Class Book < ActiveRecord::Base

has_and_belongs_to_many :categories

acts_as_list :include => :category,
:scope => :category_id

end

Thanks,
Peter

Peter M. <petermichaux@…> writes:

Hi,

I found the problem below on the Rails wiki and have the very same problem.
Can anyone suggest a solution that does not involve an extra object like
on the
wiki?

Thanks,
Peter

From: Peak Obsession

I’m looking for a Howto that would explain how to use ActsAsList where you
have something like the following:

Hi,

I just struggled through this myself, and came up with a temporary, but
relatively simple solution:

http://wiki.rubyonrails.com/rails/pages/HowToUseActsAsListWithHasAndBelongsToMany

I’m fairly new to rails and ruby, though not DBs & Web programming, so
feel free
to refine the technique where it could be made more elegant!