SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update_attribute permalink error

    Howdy,

    I'm on page 198 of the Lenz RoR book and am having a problem. I downloaded all the sample code to see if I missed anything, and everything looks fine. When in the Rails console I get an error after typing "s.update_attribute ermalink, 'my-shiny-weblog'."

    NoMethodError: undefined method `permalink=' for #<Story:0xb71b8368>
    from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1845:in `method_missing'
    from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:772:in `send'
    from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:772:in `update_attribute'
    from (irb):3
    from :0


    Can anyone point me in the right direction?

  2. #2
    SitePoint Member
    Join Date
    May 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never read the book but does the permalink field exist in your database?

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went back and manually added the permalink field. That fixed the problem, but I'm wondering what I did wrong (rails wise).

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went back and manually added the permalink field.
    Do you expect Rails to read your mind and add it for you? ;-)

    Rails reads the database table definition and defines methods for the columns, so if you don't have a particular column you won't get a method.

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought rake db:migrate would make what I defined in my migration file.

  6. #6
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a mistake in the book listed in the errata.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  7. #7
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by craystar View Post
    I thought rake db:migrate would make what I defined in my migration file.
    Oh, I didn't know you had a migration. You migration should look like this:

    Code:
    create_table :foo do |t|
      t.string :permalink
    end
    
    # or
    
    add_column :foo, :permalink, :string


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •