Help me understand dynamic layouts in Sinatra

Posted by thermans on Stack Overflow See other posts from Stack Overflow or by thermans
Published on 2010-03-17T19:47:18Z Indexed on 2010/03/17 19:51 UTC
Read the original article Hit count: 288

Filed under:
|
|

Help me understand this; I'm learning Sinatra (and Rails for that matter, er, and Ruby).

Say I'm doing a search app. The search form is laid out in one div, and the results will be laid out in another. The search form is rendered into the div by a previous view (maybe from a login form).

I want to process the form params, perform the search, and render the results into the results div.

If I have a single "yield" in the layout and render the divs from different views, the results div erases the search div when it renders.

If I define the divs in the default layout, then just render the content, obviously the layout will be messed up: there would have to be two "yields" and I don't think Sinatra supports passing blocks in to yields.

I tried foca's sinatra-content-for plugin, and that seems closer to what I need. But I can't figure out where to place the "yield_content" statements.

If I have this haml in my layout:

#search
  -# search form
  = yield_content :search
#results
  -# search results
  = yield_content :results

... this in my search view:

 - content_for :search do
 %form{:method => "post"... etc.

... and this in the results view:

- content_for :results do
%table{:class => 'results'... etc.

This sort of works but when I render the results view, the search div is emptied out. I would like to have it remain. Am I doing something wrong? How should I set this up?

© Stack Overflow or respective owner

Related posts about sinatra

Related posts about haml