my face
About Me

Published Posts

All Posts

New Post


View by Tag:

interviewing, code, testing, philosophy, blog, wantmyjob, virtualization, railsmud, heroku, ruby, published, neoarchaeology, railsgame, rails, juggernaut, astrino, cheaptoad, shannaspizza, mongodb, refactorit, devise, rvm, passenger


FeedBurner picture


Online Portfolio

Resume

Profile on LinkedIn

Recommend Me

Ruby on Rails Bug - directories and partials

Posted: 2 years ago (2008-06-23 17:11:12 UTC ) / Updated: 15 months ago (2009-06-01 22:21:37 UTC )

Imported from WordPress

Originally posted on 2008-06-23 17:11:12

I found a random Ruby on Rails (version 2.1, MacOS X 10.4, but I imagine it's been there awhile on all platforms) bug today. In hopes of making Google just slightly more all-knowing, I shall record it here for posterity.

If you're using a partial to render a chunk of a page, and you use *another* partial from that, it works fine. That's not the bug. But say you have nested partials in your "views/users/" directory called _partial1.html.erb and _partial2.html.erb, where partial1 calls partial2. If you invoke the first partial from another view, say views/home/index.html.erb, as <%= render_partial('/users/_partial1', obj) %>, you may find that partial2 can't be found.

Specifically, if you render partial2 from partial1 in the obvious way, as "<%= render_partial('partial2', obj.subpart) %>", partial2 won't be found. Partial2 will be searched for in the directory of the view that partial1 is called from, /home, not the directory where partial1 is found, /users. So if you nest partials like that, make sure to give them an explicit leading directory instead of letting Rails find them for you. Otherwise, whatever partial calls them can't be called with an explicit directory.

I call this a bug because it significantly decreases the utility of Rails finding your partials for you in the current view, and I can't imagine a real-life case where the current functionality is the right answer. It's possible I just don't fully understand the issues involved.

Previous: And then... / Next: Mocking Controller Methods for Rails Integration Testing of OpenID

Edit | Destroy | See All Posts

blog comments powered by Disqus