次のコードを使用して、デバッガー ポイントでコードを使用しようとすると (Song クラスの「rating」アクセサーを使用しようとすると)、なぜ
NoMethodError Exception: undefined method "rating" for #<Class:0xb3b7db04>
それSong.instance_methods
を明確に示して:rating
おり:rating=
、リストに載っていますか?
-
#songs_controller.rb
class SongsController < ApplicationController
def index
debugger
@ratings = Song.rating
end
end
-
#schema.rb
ActiveRecord::Schema.define(:version => 20111119180638) do
create_table "songs", :force => true do |t|
t.string "title"
t.string "rating"
end
end
-
#song.rb
class Song < ActiveRecord::Base
attr_accessor :rating
end