开发者

Overriding to_s in rails model... possible?

开发者 https://www.devze.com 2023-04-11 22:16 出处:网络
I\'ve got this model class Question < ActiveRecord::Base has_many :votes def to_s \"hello?\" end end and when I attempt to display a Question with <%= @qu开发者_如何学Pythonestion %>

I've got this model

class Question < ActiveRecord::Base

    has_many :votes

    def to_s
        "hello?"
    end
end

and when I attempt to display a Question with <%= @qu开发者_如何学Pythonestion %>

I get this...

#<ActiveRecord::Relation:0x1042b2960>

obviously I expect to get hello?


Are you sure @question is a Question? The to_s response you are getting makes me think otherwise.

#<ActiveRecord::Relation:0x1042b2960>

It looks like you have a ActiveRecord::Relation, not a Question.

0

精彩评论

暂无评论...
验证码 换一张
取 消