a good write up and an interesting discussion.
A nicely presented pdf, just, a few editorials you may like to be
aware of on Page 8, using content_for:
The second code fragment has left for right.
the penultimate para starting OK - wording of first two sentences
second column, first text para - about_right should be aboutus_right
The topic was particularly useful reading for me at the moment. I am
already doing something similar to provide a prompt/errors div/partial
that appears at the bottom of the screen. I use a partial for my own
error messages, based on the rails methods and also put flash content
into the div. I have yet to find the best way to convey the
error_messages_for information to the partial. At the moment, I set
an instance variable in the view which is picked up by the partial in
I haven't fully reviewed Rails error handling systems yet. I've always had a global error manager for that stuff so it was available to everything at any time. Error handling was always a framework-wide service in my apps. It seemed to me to be one of those things that was worth allowing all objects of the app to know about.
Also, one things Rails seems to lack is the concept of web site
modularity. If it's there's I don't see it yet. In my own framework,
if I create a news reading/writing section to a web site, that
section lives under one folder. I can literally drag and drop that
one folder from project to project and everything I need is
encpsulated (without generating redundant code from module to
module). Update the CSS, and it's ready use. So, my history with that
type of development also tends to lean on separate layouts because as
stand-alone shells, they're easier to share project to project.
I really like that idea, but I am not quite clear about what you mean
by a section living under a folder. eg What lives in the folder, and
how does it get accessed?
You can probably get a better idea of what I mean from this page:
I also like your point about separate
layouts. Having an app that has now grown, I can see the sense in
splitting this even with very similar layouts, just to make the css
more manageable - thanks, I find examples of how others structure
things really useful.
Yeah at some point, one layout with a boatload of conditional and modal clag hanging about just doesn't make sense to me. Takes longer to find what need to be changed than it does to maintain a few very simple duplicates. DRY is only useful if it saves you time & hassle.
At the moment, I have just started experimenting with redBox modal
popup boxes eg. to provide lookups for complex forms. This has given
me a nice product, but a bit of a headache managing partials and
controllers. I wanted to abstract out some parts of the handling such
as look ups using auto_completer, edit and new. For example, trying
to have common partials for customer where they can be used in
different contexts, eg orders, repairs etc. Although I have got it
working, I feel like I have begun to introduce spaghetti partials.
with one linking to another etc. This also causes a headache of which
controller things go in and calling partials from different
controllers also gives problems if the right parts of the view are not
correctly rewritten, the submit/link to remote can end up making the
request to the wrong controller. I dont have any wisdom in this area,
I am still thinking it through.
At some point you have to think about the difference between when partials _can_ be reused because they happen to be similar vs when they _should_ be reused because you really do want where they're applied to stay identical. I've seen cases where people pull out code to be shared because it happened to be the same at that point, but it wasn't stuff that particularly needed to stay the same and indeed was subject to evolving design whim. Something to think about if applicable.
If you end up with partials that have conditional code in them to do X vs Y based on how they got called, or who they got called by, all that kind of code belongs back up in the controller (sometimes in a helper). It's possible you have a case where there is a lot of view logic. Post controller, but pre view logic that will feel out of place in either Rails box. In that case you generate another layer of logic beteeen the two so both controllers and views can stay clean. This can happen when you're developing apps that deliver to standard browser and mobile browsers. If your controllers are particularly complex with data management, it can be nice to not have to bulk them up with a lot of decision making about the display. So you push that off to another layer. Most web apps really don't need that, but some would. If anything, just think about whether you're ending up with code in partials that belong in controllers. You may need to create small methods in the application.rb file that handle those decisions and any re-mapping of data structures or object names to allow the partials to be usable by multiple controllers. And of course, if yo find yourself reusing partials, sometimes you go back and refactor your data structures because you've now learned they really are the same or similar things, so you can rename them to reflect that (and make them easier to pass to partials).
Anyway, just shootin' from the hip here...