2013-12-08 24 views
0

我有question_options有很多關係的問題模型。有條件簽到rabl

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 

在我question_detail Rabl的我有

object @question 
attributes :id, :status 
child :question_options do 
attributes :question_id,:option,:order,:is_other 
end 

在這裏,我想只響應其中有is_other =假

like the below.... 
    object @question 
    attributes :id, :status 
    child :question_options do 
    attributes :question_id,:option,:order,:is_other = true 
    end 

如何question_option d o我檢查一個條件是什麼?

+0

您是否試圖限制Question或QuestionOptions的渲染? – phillbaker

+0

是@phillbaker我想限制一個條件questionoption。我需要獲取在is_other字段中有效的問題選項 – ferdy

回答

1

一個簡單的方法來做到這一點是如果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 

還檢查了section on conditions