我已经在我的model/user.rb
class User < ActiveRecord::Base
attr_accessible :name, :has_car
def init(age)
if age > 18
has_car = true
else
has_car = false
end
has_car
end
...
然后在我看来(.html.haml
文件),我试图只打印该字段:
...
%li
- if this_user.has_car
= "This person has a car"
- else
= "This person does NOT have a car"
...
出于某种原因,this_user.has_car
总是评估为false
。谁能告诉我我在这里做错了什么?(我对 Ruby/Rails 很陌生)
谢谢