我可能会对此完全错误
我想要做的是下面的代码,其中when_appointment是一个布尔值。
def create
@visit = Visit.create(visit_params)
if visit.when_appointment == "true"
redirect_to new_appointment_path
else
redirect_to new_chat_path, :notice => "User updated."
end
end
答案 0 :(得分:2)
在红宝石中:
true == 'true'
# => false
分配后,和Rails类型转换属性,所以如果你有:
visit_params[:when_appointment]
# => "true"
或
visit_params[:when_appointment]
# => "1"
你会得到:
visit = Visit.new(visit_params)
visit.when_appointment
# => true
所以,回到你的问题,你应该:
if visit.when_appointment
# ...
else
# ...
end