NoMethodError (undefined method `length=' for #<Tour:0x000000081583f0>):

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:inblock 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:infind_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?

On 28 March 2013 13:07, [email protected] wrote:

`find_or_create_by_guide’
to bookless
t.pace = guide.pace || :normal
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

Hey, thanks for the answer.

As for the Book.rb - yes, it’s a typing error.

When I run Book.first.length in the rails console, I get:

1.9.3-p327 :001 > Book.first.length
Book Load (0.2ms) SELECT “books”.* FROM “books” WHERE “books”.“label”

'app LIMIT 1
=> nil

And yes, I did run the migration.

I think the problem can lie in Mongo collections. I’ve added the
“length”
collection by updating an already working Mongo Document. Maybe that’s
the
problem? I’ll try to set up another mongo document with the length
collection only.

class Guide::Document
include MongoMapper::Document

key :city, Integer
key :trips, Array
key :themes, Array
key :places, Array
key :pace, String
key :date_from, Time
key :date_to, Time
key :host, String

  • key :length, Integer*
    timestamps!
    end

W dniu czwartek, 28 marca 2013 16:52:13 UTC+1 uytkownik Colin L.
napisa:

On 29 March 2013 09:57, [email protected] wrote:

Hey, thanks for the answer.

As for the Book.rb - yes, it’s a typing error.

When I run Book.first.length in the rails console, I get:

1.9.3-p327 :001 > Book.first.length
Book Load (0.2ms) SELECT “books”.* FROM “books” WHERE “books”.“label” =
'app LIMIT 1

Why does that include a WHERE clause? and why is it looking for label =
'app

Colin

This is because we have a whitelabel feature in our app, and therefore
most
columns and tables are labelled to. The label “app” simply means that it
loads all the data from our main app.

W dniu pitek, 29 marca 2013 11:48:56 UTC+1 uytkownik Colin L. napisa:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs