title: Multiple layouts in rails [Newbie Q]
body: <p>As a newb, I decided to build a "home inventory" application. I am now stuck on how to programmatically select a layout based on what type of item it is when viewing it in a browser.</p>
  
  <p>According to my planning, so far I  should have created a few models to represent types of items I can find in my home: <strong>Furniture</strong>, <strong>Electronics</strong> and <strong>Books</strong>.</p>
  
  <pre><code>class Book &lt; ActiveRecord::Base
  end
  
  class Furniture &lt; ActiveRecord::Base
  end
  
  class Electronic &lt; ActiveRecord::Base
  end
  </code></pre>
  
  <p>Now the <strong>Books</strong> model has things like <em>isbn</em>, <em>pages</em>, <em>address</em>, and <em>category</em>.
  <strong>Furniture</strong> model has things like <em>color</em>, <em>price</em>, <em>address</em>, and <em>category</em>.
  <strong>Electronics</strong> has things like <em>name</em>, <em>voltage</em>, <em>address</em>, and <em>category</em>.</p>
  
  <p><strong>Here is where I got confused</strong>. I know the property <em>address</em> is going to be the same for all of them. I also know that, I will need to create multiple "layouts" for 3 different types of items to show the different properties of said items with appropriate graphics and stylesheets.</p>
  
  <p>But how will I go about deciding which category the item is so I can determine which layout to render.</p>
  
  <p>According to me, this is how I will do it:</p>
  
  <pre><code>class DisplayController &lt; ApplicationController
  def display    
    @item = Params[:item]
      if @item.category  = "electronics"
     render :layout =&gt; 'electronics'
    end
  end
  </code></pre>
  
  <p>In my routes.rb</p>
  
  <pre><code>map.display ':item', :controller =&gt; 'display', :action =&gt; 'display'
  </code></pre>
  
  <p>I only seem to have one concern with this, I probably will add a lot of categories later on and think there should be a more DRY-esque way of dealing, rather than hardcoding them.</p>
  
  <p>I understand that I need to add into my layout html tags to display relevant information for that particular category.</p>
  
  <p>----<strong>Questions</strong>----</p>
  
  <ol>
  <li>Is this the right way to approach this type of problem.</li>
  <li>Will this approach be compatible when I decide to add a gem like <em>thinking_sphinx</em> to run search.</li>
  <li>What issues do you see with my approach and how can I make it better.</li>
  <li>I was reading something about "Polymorphic Assoc", does that apply in this case, since category exist for all items?</li>
  </ol>
  
  <p>Also, I was trying to get a routes to render a URL like "<a href="http://localhost/living-room-tv" rel="nofollow noreferrer">http://localhost/living-room-tv</a>"</p>