Forum: Ruby on Rails acts_as_list with has_and_belongs_to_many

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.
petermichaux (Guest)
on 2005-11-18 23:12
(Received via mailing list)
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: http://wiki.rubyonrails.com/rails/pages/HowtoUseActsAsList
 I'm looking for a Howto that would explain how to use
ActsAsList<http://wiki.rubyonrails.com/rails/pages/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.
gedwards (Guest)
on 2005-11-19 01:01
(Received via mailing list)
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
removed_email_address@domain.invalid
http://www.eyetools.com



 -----Original Message-----
From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid]On Behalf Of Peter M.
Sent: Friday, November 18, 2005 1:10 PM
To: removed_email_address@domain.invalid
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: http://wiki.rubyonrails.com/rails/pages/HowtoUseActsAsList

  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.
petermichaux (Guest)
on 2005-11-19 02:53
(Received via mailing list)
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
indyjones48 (Guest)
on 2005-11-24 04:56
(Received via mailing list)
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: http://wiki.rubyonrails.com/rails/pages/HowtoUseActsAsList
>
>
> 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/HowToUseAc...

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!
This topic is locked and can not be replied to.