我的问题模型与question_options有很多关系。
class Question < ActiveRecord::Base
#relationship
belongs_to :user
has_many :question_options, :dependent => :destroy,:conditions => "is_deactivated is FALSE"
问题选项
class QuestionOption < ActiveRecord::Base
attr_accessible :question_id,:option,:order,:is_other,:is_deactivated
belongs_to :question
在我的问题_detail rabl我有
object @question
attributes :id, :status
child :question_options do
attributes :question_id,:option,:order,:is_other
end
这里我只想回复is_other = false
的question_optionlike the below....
object @question
attributes :id, :status
child :question_options do
attributes :question_id,:option,:order,:is_other = true
end
如何检查rable中的情况?
答案 0 :(得分:1)
一种简单的方法是使用if if
option on attributes
,例如:
object @question
attributes :id, :status
child :question_options do
attributes :question_id,:option,:order,:is_other,
:if => lambda { |question_option| question_option.is_other }
end