Ruby on Rails Thursday, March 28, 2013

On 28 March 2013 13:07, <maciej.mietek@timeself.pl> wrote:
> Hey
>
> I have a problem with nomethoderror and have no idea how to solve it.
>
> In logs:
>
> NoMethodError (undefined method `length=' for #<Book:0x000000081583f0>):
> 2013-03-28T12:38:35+00:00 app[web.2]: app/models/engine/book.rb:13:in
> `block in find_or_create_by_guide'
> 2013-03-28T12:38:35+00:00 app[web.2]: app/models/engine/book.rb:9:in
> `find_or_create_by_guide'
> 2013-03-28T12:38:35+00:00 app[web.2]:
> app/controllers/guide_controller.rb:37:in
> `find_or_create_book_based_on_guide'
>
> cache: [GET /en/books/planner/preview] miss
> 2013-03-28T12:38:35+00:00 app[web.2]: Processing by BooksController#preview
> as */*
> 2013-03-28T12:38:35+00:00 app[web.2]: Parameters: {"locale"=>"en",
> "id"=>"planner"}
> 2013-03-28T12:38:35+00:00 app[web.2]: Unknown label 'www'. Switching label
> to bookless
> 2013-03-28T12:38:35+00:00 app[web.2]: Finded book #515439c0e622d90002000019
> 2013-03-28T12:38:35+00:00 app[web.2]: Completed 500 Internal Server Error in
> 82ms
>
> Book.rb:
> module ClassMethods
> def find_or_create_by_guide(guide)
> book = ::Book.find_or_create_by_document(guide.id.to_s) do |t|
> t.city_id = guide.city
> t.host = guide.host
> t.pace = guide.pace || :normal
> t.length = guide.length
> end
> Later in Book.rb, I have:
>
> groups = sorted_points.in_groups_of(length, false)
>
>
> In Book.rb I have attr_accessible :length. I've also updated the table with
> length column:
> class AddLengthColumnToBooks < ActiveRecord::Migration
> def change
> add_column :books, :length, :integer
> end
> end
>
> I have no idea what's going on. Can someone please help me with this?

The error refers to book.rb but you refer to Book.rb. Is that just a
typing error?

What happens if, in the Rails Console you do
Book.first.length

I presume you have run the migration. Have you checked using a
database tool that the column exists?

I wonder whether length is a reserved word. If all else fails try a
different name.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment