Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6548357

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:56:28+00:00 2026-05-25T11:56:28+00:00

I’ve come across an oddity that I can’t quite explain with regards to Rails

  • 0

I’ve come across an oddity that I can’t quite explain with regards to Rails 3 and rendering partials with layouts (from the controller). I’m hoping someone can provide a little insight into what’s happening.

First off, we’ll call this controller a “legacy” controller. It’s been around for a long time and is doing a lot of things wrong, but I’m not looking to refactor it at this point so I’m trying to find ways to work with what we have.

The new action is something like this (in the BarsController)

def new
  if something
    render :partial => "foo", :layout => "bars"
  elsif something_else
    render :partial => "foo2", :layout => "bars"
  elsif something_else_else
    render :partial => "foo3", :layout => "bars"
  else
    render :partial => "foo4", :layout => "bars"
end

Now, in Rails 2.3.5, this worked fine. It would render the appropriate partial inside the appropriate layout — I realize the layout option is redundant here as it would default to the bars layout regardless. When we upgraded to Rails 3.0.x, we started getting errors as follows:

Missing partial layouts/bars with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html]

Clearly the layouts/bars.html.erb file is and always has been there, so I couldn’t figure it out. I was able to render with :layout => false, but that of course wasn’t going to work. Eventually I figured out that if I do either of the following, it works:

1) Rename my layout to _bars.html.erb instead of bars.html.erb and:

render :partial => 'foo2', :layout => 'bars'

2) Keep my layout as bars.html.erb (what I want) and :

render '_foo2' # :partial option is redundant here anyway


It seems as though by using the :partial option instead of the string as first parameter is causing rails to apply the _name.html.erb convention to both the partial AND the layout. If I put in the underscore on my own, it falls back to the behaviour I expected which is to not prepend an _ infront of the name of the layout.

Does anyone know why this is the case?


EDIT Alright, not sure how I missed this… but here’s something in the docs making mention of this. It seems as though it’s been around since 2.3.8, perhaps it was done differently in 2.3.5 (what we were running on)?

3.4.3 Partial Layouts

A partial can use its own layout file, just as a view can use a
layout. For example, you might call a partial like this:

<%= render “link_area”, :layout => “graybar” %> This would look for a
partial named _link_area.html.erb and render it using the layout
_graybar.html.erb. Note that layouts for partials follow the same
leading-underscore naming as regular partials, and are placed in the
same folder with the partial that they belong to (not in the master
layouts folder).


  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.