Friday, 15 March 2013

ruby on rails - Conditionally include child nodes with RABL -


I think I have a very basic case when I return to JSON for standard restored controller methods I am using rabl ...

First we say that with my parents and children is a typical one for many relatives (let's say the customer and accounts):

  class clients & lt; ActiveRecord :: Base is has_many: accounts end   

For the customer, I am indexed and edited in my controller - the index where I just want to return all the customers (without accounts) And edit where I have to go back with a specific client index along with all their accounts, I do not want to return the accounts for obvious execution (N + 1) reasons.

In my Rabble, I have the following:

  #index Rabl (to list all customers) Archive: @ Customer "customer / _customer"   

and

  # edit.rabl (for editing a single client) Object: @ Customer Expands "Customer / _customer" < / Code>  

I am reusing _customer.rabl for both index and editing.

  #_ customer.rabl Item: @ Customer Attributes: Name, ...... If @include_accounts Child: "Account / _account" end of expiry ends in accounts   

I do not work on these included_count (controller) and not indexes included in my edit - essentially the frequency here (@include_accounts) never passes down. What is the correct pattern to implement it?

Although rail-rabl gem claims that it is fast, I came to know that templates are not flexible For conditional expression - see rabl-rails readme re: example variable.

1 comment:

  1. Giuseppe: Ruby On Rails - Conditionally Include Child Nodes With Rabl - >>>>> Download Now

    >>>>> Download Full

    Giuseppe: Ruby On Rails - Conditionally Include Child Nodes With Rabl - >>>>> Download LINK

    >>>>> Download Now

    Giuseppe: Ruby On Rails - Conditionally Include Child Nodes With Rabl - >>>>> Download Full

    >>>>> Download LINK cF

    ReplyDelete