import .rb files in other .rb files (for the 'view')

0 views
Skip to first unread message

Luca Scaljery

unread,
Dec 14, 2006, 4:16:07 PM12/14/06
to rubyonra...@googlegroups.com
Hi All


I have a complex structure (a lot of <div>'s) which occures in a couple
of views.

I think I red somewhere that it is possible to put this structure in a
seperate .rb file, which can then be included into the other (.rb)
files.

Can someone point me into the right direction of how to do this ??

Thnx a lot
LuCa

--
Posted via http://www.ruby-forum.com/.

Alex Wayne

unread,
Dec 15, 2006, 12:35:00 AM12/15/06
to rubyonra...@googlegroups.com
Luca Scaljery wrote:
> Hi All
>
>
> I have a complex structure (a lot of <div>'s) which occures in a couple
> of views.
>
> I think I red somewhere that it is possible to put this structure in a
> seperate .rb file, which can then be included into the other (.rb)
> files.
>
> Can someone point me into the right direction of how to do this ??
>
> Thnx a lot
> LuCa

Partials are your friend.

#app/views/foo/index.rhtml
<% @items.each do |item| %>
<%= render :partial => 'item', :locals => {:item => item} %>
<% end %>

#app/views/foo/_item.rhtml
<div class="item">
<h1>Item #<%= item.id %></h1>
<%= textilize(item.description) %>
</div>

Reply all
Reply to author
Forward
0 new messages