2

Hi I am new to Ruby on Rails and I am following Michael Hartl's book online. In Partials section of his book. The code he used to render partial was

<%= render 'layouts/stylesheets' %>

but I get this error.

I read the API and tried this

<%=render :partial => "/layouts/stylesheets" %>
but still can't figure this one out.

Thanks for all the help!

markphd
  • 1,394
  • 1
  • 12
  • 17

2 Answers2

5

In your view, make sure you have the following structure:

- views
  - layouts
    - application.html.erb
    - _stylesheets.html.erb

Your code should be:

<%= render 'layouts/stylesheets' %>

If your main template is inside the layouts folder:

<%= render 'stylesheets' %>
Ben
  • 1,370
  • 17
  • 42
  • When I remove the path before stylesheets, i get this error Missing partial pages/stylesheets, application/stylesheets with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. – markphd May 30 '12 at 16:26
  • 1
    Thanks for the response I finally solved it! It was caused by a simple mispelled file. :( – markphd May 30 '12 at 18:05
  • Rails searches for partials in views... so, as far as I know, if you have your partials inside layouts, you always need to tell him to look inside that directory. I might be wrong... – Luis Ortega Araneda May 20 '13 at 15:27
1

I overlooked the filename. When I initially created the file, after the .erb extension, I accidentally put a space after.

markphd
  • 1,394
  • 1
  • 12
  • 17