# Simple question about showing results

**URL:** <https://www.ruby-forum.com/t/simple-question-about-showing-results/92677>\
**Category:** Rails\
**Created:** [April 23, 2007, 12:29am UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677 "2007-04-23T00:29:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![supaspoida](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@supaspoida](https://www.ruby-forum.com/u/supaspoida)\
**Post date:** [April 23, 2007, 12:29am UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677/1 "2007-04-23T00:29:07Z")

</div>

Hello,

I’m new to Ruby on Rails and am working on my first major app. I’m  
having a bit of trouble figuring out the best way to do some things. The  
first issue I’m having is regarding an events page. I have 3 divs on my  
page, that will each display different levels of event details in  
different formats. For example, the first one will show all of the event  
details in a very graphical format. The next div will show only the next  
5 events with only the event name and date and a smaller picture. The  
final div will show the rest of the events in table form, and be able to  
paginate through the whole result set. I hope to eventually have it  
display in a calendar format.

I will be using partials within each div to display the appropriate list  
format (thanks to reading through this forum!).

In my event controller I’ve got the list action that was generated by  
the scaffold, and contains all the results paginated. My question is  
this: is there any way to use the result set from this list to populate  
all three divs, limiting the result set on a case by case basis, or  
should I be writing separate actions for each type of listing? If it is  
possible to limit which results are shown on the view (partial) level,  
how would I go about that?

Sorry for the lengthy post, just wanted to be clear about what I am  
trying to accomplish! Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![supaspoida](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@supaspoida](https://www.ruby-forum.com/u/supaspoida)\
**Post date:** [April 23, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677/2 "2007-04-23T17:28:35Z")

</div>

Sorry to bump this, just haven’t been able to find a solution and was  
hoping you guys had some ideas. If there is some more information or  
clarification that you need from me, please let me know and I can  
provide it.

Thanks!

---

<div class="post-metadata">

**Author:** ![supaspoida](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@supaspoida](https://www.ruby-forum.com/u/supaspoida)\
**Post date:** [April 23, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677/3 "2007-04-23T21:11:46Z")

</div>

this isn’t much of an answer, but you might want to look into  
content\_for, per this blog:

[http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up](http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up)

And, if you can make your database fit into acts as nested\_set, it  
makes life much easier (tho not that easy to get existing table into  
the parent, root, rgt and lft fields).

On Apr 22, 3:29 pm, Lar Van der jagt \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> paginate through the whole result set. I hope to eventually have it  
> display in a calendar format.
> 
> I will be using partials within each div to display the appropriate list  
> format (thanks to reading through this forum!).

---

<div class="post-metadata">

**Author:** ![supaspoida](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@supaspoida](https://www.ruby-forum.com/u/supaspoida)\
**Post date:** [April 23, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677/4 "2007-04-23T23:35:54Z")

</div>

Thank you for your response!

That is not specifically what I was looking for, but is very helpful.  
Previously I was setting instance variables using render\_to\_string with  
partials for left, right, and bottom content. I will try out this  
method, which looks much more elegant. It seems I would then be calling  
the partials from the view, rather than the controller.

The more research I do, the more it seems like I will have to have  
different Event.find conditions for each method of displaying events. It  
also seems like I should be putting these methods into the model. It is  
pretty clear that I’ve still got a lot to learn when it comes to Ruby on  
Rails. I worked through the Agile Rails book and had no problem putting  
together the depot app, but applying that knowledge seems to be harder  
than I thought.

removed\_email\_address@domain.invalid wrote:

> this isn’t much of an answer, but you might want to look into  
> content\_for, per this blog:
> 
> [http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up](http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up)
> 
> And, if you can make your database fit into acts as nested\_set, it  
> makes life much easier (tho not that easy to get existing table into  
> the parent, root, rgt and lft fields).

---

<div class="post-metadata">

**Author:** ![supaspoida](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@supaspoida](https://www.ruby-forum.com/u/supaspoida)\
**Post date:** [April 24, 2007, 8:08am UTC](https://www.ruby-forum.com/t/simple-question-about-showing-results/92677/5 "2007-04-24T08:08:19Z")

</div>

I have been trying to follow the technique outlined in the dirty views  
blog post, but ran into a problem.

That is assuming that the \<%= yield :left %\> etc are on the same page as  
my main layout with a standard \<%= yield %\>. I am trying to use a  
template within the layout, with \<%= yield :left %\> called from that  
template. When I try to call the template using render :template =\>  
‘shared/right\_col/test’ I get the html for the template but with none of  
the content defined in my div. Here is the code:

view (test.rhtml):

\<% content\_for :left do %\>  
Left content  
\<% end %\>

\<% content\_for :right do %\>  
Right content  
\<% end %\>

\<% content\_for :bottom do %\>  
Bottom content  
\<% end %\>

test

Controller method:  
def test  
:template =\> ‘shared/right\_col/test’  
end

template (shared/right\_col/test.rhtml)

 \<% yield :left %\> 

 \<%= yield :right -%\> 

 \<%= yield :bottom -%\> 

The reason I want to split the layout into two parts is because I have  
four basic types of header/footer types of layouts that will be used  
across the site, and then could have any number of different types of  
content layouts. I would rather not have to have a whole new layout for  
each different type of content layout. Any ideas how to make this work?
