On Fri, Nov 7, 2008 at 7:28 AM, Tom Ha <[EMAIL PROTECTED]>wrote:
> @books: array of books
> @books.each do |book|
> do stuff...
> do stuff...
> do stuff...
> book["number_of_pages"] = 123 #this is supposed to "inject" the
> key/value pair
> end
> -> "inject" the key 'number_of_pages' with the value '123' into the hash
> "book" ("book" IS a hash, right?), for every book in @books
No, book is a class, I assume at least.
Probably in your models directory you have a book.rb file that has
class Book < ActiveRecord::Base
<stuff>
end
-> Then, show in the view: All "Number of pages": <%= @books.collect
> {|b| [b.number_of_pages] } %>
>
> It doesn't work like this... (-> "undefined method `number_of_pages' for
> #<Book:0xb5c022bc>")
>
You probably want a column called number_of_pages in your books table
Then you can do:
book.number_of_pages = 123
book.number_of_pages #=> 123
Hope that helps
Mikel
--
http://lindsaar.net/
Rails, RSpec and Life blog....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---