This may seem like, and probably is, so elementary that it isn’t worth writing about. I poked around on Google for a bit and couldn’t find the answer though, so it might be worth sharing. Basically I have a Ruby on Rails application with a controller whose corresponding views directory is getting hard to look at. For all my bazillions of partials I prefix them with something so they sort together _pet_detail_comments.rhtml, _pet_detail_properties.rhtml. You get the idea.

As I approach 30 views in one directory though, it starts to get hard to look at. I am an organization freak, so I want to group partials by context and put them in subdirectories:


When you render the partial you have to use the full path of: controller/subdirectory/partial_or_view. At first I wasn’t using the controller in the path, and you need it for this to work, apparently. So rendering a partial looks like this:

  1. page.replace_html "pet_comments", :partial => "petstore/detail/comments", :locals => {:pet => @pet}

Rubyists always talk about clean, easy to read code. I have always thought that this sort of thing is just as important. Happy organizing.