title: Filtering nested attributes in rails API json output
body: <p>Im building an API in which i have a model called Studio. Studio has many movies and many series, and movies and series have many characters of their own. Also, a character can be in many movies and/or many series, and belongs to a studio.
  I got all the models relational tables logistics figured out by now, but what i'm trying to do right now, i can't think of a way.</p>
  <p>So my routes are designed so i can do something like localhost:3000/api/v1/studios/1/characters -&gt; this way i display all the studio's (studio_id: 1) characters (from all the movies and series that belong to that studio).
  That is fairly easy with just doing something like:</p>
  <pre><code>@characters = Character.where(studio_id:@studio.id)
  </code></pre>
  <p>In my CharactersController, where i have</p>
  <pre><code>def get_studio
      @studio = Studio.find(params[:studio_id])
  end
  </code></pre>
  <p>Now i am trying to design the logistics so i can do <code>localhost:3000/api/v1/studios/1/seriees/1/characters</code>
  And only get the characters from that specific seriees. <code>localhost:3000/api/v1/studios/1/movies/1/characters</code> should also be valid.</p>
  <p>I tried</p>
  <pre><code>def get_movie
      @movie = Movie.find(params[:movie_id])
  end`
  </code></pre>
  <p>and</p>
  <pre><code>def get_serie
      @serie = Seriee.find(params[:seriee_id])
  end
  </code></pre>
  <p>in my CharactersController, with <code>before_action :get_serie</code> and <code>before_action :get_movie</code> at the very start of the code, but it gives me an error because i'm never getting both a movie_id and a seriee_id, it's either one or the other, so it can't search for both at the same time.</p>
  <p>The POST from character i will only do from <code>localhost:3000/studios/1/characters</code> so that's not a problem, i only want to be able to GET from <code>localhost:3000/studios/1/movies/1/characters</code> and <code>localhost:3000/studios/1/seriees/1/characters</code></p>
  <p>I hope i didn't ramble to much and you are able to understand me. If you think that my way of solving this problem is just not right, please tell me as i am just learning and any advice would be very valuable.</p>