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.
on 2007-04-23 00:29
on 2007-04-23 17:28
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!
on 2007-04-23 21:11
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... 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> 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!).
on 2007-04-23 23:35
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. email@example.com 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... > > 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 2007-04-24 08:08
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) <div id="content"> <div id="left_wrapper" class="wide"> <div id="left" class="wide"> <% yield :left %> </div> </div> <div id="right" class="wide"> <%= yield :right -%> </div> <div id="bottom"> <%= yield :bottom -%> </div> </div> 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?