how can i get the values using include with conditions in rails? -


i have shop has_many association , include items items belonging shop received

 format.json { render json: {:shop => @shops.as_json(:include => :items)}} 

now gives items belongs shop want items specific condition, item_type = "accessories". how can this? please me.

edit

i have put new question in how value of include conditions?

you should filter data activerecord, , call as_json on filtered data.

you can like:

@shops = shop.includes(:items).where("items.itemp_type = ?", 'accesories') format.json { render json: { :shop => @shops.as_json(:include => :items) } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -