0

レール開発に関しては非常に新しいです

レール 3.2.13 / ルビー 1.9.3

私はこのモデルを持っています

class Post < ActiveRecord::Base
    attr_accessible :content, :title
    attr_accessor :testing

    def asignar
        title = "hey"
    end
end

そして、Rails コンソールに移動すると:

irb(main):004:0* post = Post.new
=> #<Post id: nil, title: nil, content: nil, created_at: nil, updated_at: nil>
irb(main):005:0> post.asignar
=> "hey"
irb(main):006:0> post.title
=> nil

これは正常ですか? 属性を取得できるように、常にオブジェクトを保存する必要がありますか?

4

1 に答える 1

4

これを試して:

def asignar
    self.title = "hey"
end
于 2013-04-16T18:57:00.737 に答える