views:

36

answers:

1

I have the following problem. My App (a prototype of an api) should be able to react on params (like language). I'm already able to respond to an request by sending an entierly object (with associated objects included) as JSON. But now i want to select the associated objects by parameter. my code:

object.to_json(include => {
   :texts_in_diff_languages => {
     #here i should be able to select only languages equal to a given parameter (params[:language])
   }
})

Do you have any idea? Thanks!

A: 

Ok i try to explain it another way round: I have three tables, one called books, called texts and the third languages. On Book has_many texts and one text has one language. Now I want to write a method in the BooksController which returns a JSON containing only the book:title, book:text:content of a specific language. This language i want to get from a parameter (params[:language_id]). Do you understand it now?

my code: (selects a book and includes all its texts for all languages)

render :json => @book.to_json(
 :only => [:title],
 :include => { 
  :texts => {
   :include => {
    :languages
   }
  }
 })
Sebastian