title: Two different layouts with one stylesheet for each
body: <p>I have two different layouts and two different stylesheets (one for each) used by one controller/action.</p>
  
  <p>How can I prevent the following error?</p>
  
  <p><strong>line #5 raised:</strong> <code>app/assets/stylesheets/application.css has already been required</code></p>
  
  <p>app/views/layouts/application.html.erb</p>
  
  <pre><code>2: &lt;html&gt;
  3: &lt;head&gt;
  4:   &lt;title&gt;Blog&lt;/title&gt;
  5:   &lt;%= stylesheet_link_tag    "application" %&gt;
  6:   &lt;%= javascript_include_tag "application" %&gt;
  7:   &lt;%= csrf_meta_tags %&gt;
  8: &lt;/head&gt;
  </code></pre>
  
  <p>The same error occurs when the other layout is loaded, but <code>"application"</code> is then <code>"another_stylesheet_file_in_the_same_folder"</code>.</p>
  
  <p>What I don't understand is why the <em>application.css</em> file was able to be loaded while the second layout has another <code>&lt;%= stylesheet_link_tag "another_css_file" %&gt;</code> line in there instead.</p>
  
  <p>Could the reason be the asset pipeline which is loading both of these stylesheets?
  Or is it just an inheritance issue?</p>
  
  <p>posts_controller.rb</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    layout :choose_layout
  
    def choose_layout
      current_uri = request.env['PATH_INFO']
      if current_uri.include?('diashow')
        @diashow = true
        return 'diashow'
      else
        @diashow = false
        return 'application'
      end
    end
  ...
  </code></pre>
  
  <p>Is the application layout already loaded before this code has been executed?</p>
  
  <p>Is there a way to solve this by using the <code>before_filter</code>?
  Or is it just stupid what I try to do? :)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Rails console:</p>
  
  <pre><code>Rendered posts/index.html.erb within layouts/application (10.4ms)
  Compiled application.css  (2ms)  (pid 23453)
  Compiled diashow.css  (1ms)  (pid 23453)
  Completed 500 Internal Server Error in 348ms
  </code></pre>
  
  <p>Why is it loading both of these files? It should only load one of them.</p>