# Need to DRY views for a global menu

**URL:** <https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813>\
**Category:** Rails\
**Created:** [March 9, 2010, 1:21am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813 "2010-03-09T01:21:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 1:21am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/1 "2010-03-09T01:21:24Z")

</div>

Hi All,

I’ve got a bunch of views for Vendors and Users, e.g. app\views\vendors  
\index.html.erb:

# Listing vendors

```
        <div id="menu">
<%= link_to 'Vendor', :controller=>'vendors',
           :action=>'index' %> &nbsp;
<%= link_to 'User', :controller=>'users',
           :action=>'index' %> &nbsp;
  </div
  <br/>

```

\<% @vendors.each do |vendor| %\>

[snip]

I pasted the div “menu” into all the views. When I change that menu,  
I’ve got to change all of them. Pretty bad, eh?

I’ve also got that menu in app\views\layouts\menu.html.erb.

Can I replace the div I pasted in manually with some kind of “include”  
referencing that .erb? I tried a bunch of ways to no avail.

Thanks in Advance,  
Richard

| Nickname | Qbname |
| --- | --- |
| \<%=h vendor.nickname %\> |

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 1:57am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/2 "2010-03-09T01:57:43Z")

</div>

On Mon, 2010-03-08 at 16:20 -0800, RichardOnRails wrote:

> ```
> <%= link_to 'User', :controller=>'users',
> 
> ```
> 
> \<% @vendors.each do |vendor| %\>  
> Can I replace the div I pasted in manually with some kind of “include”  
> referencing that .erb? I tried a bunch of ways to no avail.

* * *

> **[ActionView::Base](https://api.rubyonrails.org/classes/ActionView/Base.html)**
>
> Action View Base Action View templates can be written in several ways. If the template file has a .erb extension, then it uses the erubi template system which can embed Ruby into an HTML document.

you need to use ‘templates’ but this is rather elemental and suggests  
that you need to check out more basic tutorials or possibly AWDWROR  
(Agile Web D. With Ruby on Rails)

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 3:54am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/3 "2010-03-09T03:54:11Z")

</div>

Hi Craig,

Thanks for your response.

> you need to use ‘templates’ but this is rather elemental

You’re spot on. This is my first “real” Rails app (for my son who  
runs a couple of private schools). So I’d like to get this working in  
a timely but correctly implement fashion.

Following your link, I modified my working module app\views\vendors  
\index.html.erb as follows

h1\>Listing vendors

```
        <div id="menu">
<%= link_to 'Vendor', :controller=>'vendors',
           :action=>'index' %> &nbsp;
<%= link_to 'User', :controller=>'users',
           :action=>'index' %> &nbsp;
  </div
  <br/>

       <%= render "shared/menu" %>
  <br/>

```

[snip]

I left in my working menu div and hoping my menu.html.erb or menu.erb  
files in app\views\shared will be invoked.

Sadly, I got:  
ActionView::MissingTemplate in Vendors#index

Showing app/views/vendors/index.html.erb where line #11 raised:

Missing template shared/\_menu.erb in view path app/views

Extracted source (around line #11):

8: \</div  
9:   
  
10:  
11: \<%= render “shared/menu” %\>  
12:  
13:

  
14: 

Can you spot where I erred?

Again, thanks in advance for any guidance you may offer.

Best wishes,  
Richard

|
| |

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 4:08am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/4 "2010-03-09T04:08:14Z")

</div>

On Mon, 2010-03-08 at 18:52 -0800, RichardOnRails wrote:

> Following your link, I modified my working module app\views\vendors
> 
> 12:
> 
> > > ```
> > > <%= link_to 'Vendor', :controller=>'vendors',
> > > 
> > > ```
> > > 
> > > I've also got that menu in app\views\layouts\menu.html.erb.
> > 
> > > Can I replace the div I pasted in manually with some kind of “include”  
> > > referencing that .erb? I tried a bunch of ways to no avail.
> > 
> > ----[ActionView::Base](http://api.rubyonrails.org/classes/ActionView/Base.html)
> > 
> > you need to use ‘templates’ but this is rather elemental and suggests  
> > that you need to check out more basic tutorials or possibly AWDWROR  
> > (Agile Web D. With Ruby on Rails)

* * *

it’s telling you exactly what the problem is…

Missing template shared/\_menu.erb in view path app/views  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 4:46am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/5 "2010-03-09T04:46:17Z")

</div>

OK Craig,

I got it: I missed the \_ in the name. Problem solved. Thank you very  
much for your help.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 9, 2010, 4:21am UTC](https://www.ruby-forum.com/t/need-to-dry-views-for-a-global-menu/184813/6 "2010-03-09T04:21:07Z")

</div>

Thanks again, Craig.

I saw and understood and tried to respond to that message. Following  
is the a session in a Command Window on my Win-XP/SP3 system that seem  
to provide the alleged missing code:

K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\>cd app\views\shared

K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\app\views\shared\>dir  
Volume in drive K is K02-100G\_NT  
Volume Serial Number is B00C-F65F

Directory of K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\app\views\shared

03/08/2010 09:48 PM .  
03/08/2010 09:48 PM …  
03/08/2010 12:54 PM 210 menu.erb  
03/08/2010 12:54 PM 210 menu.html.erb  
2 File(s) 420 bytes  
2 Dir(s) 58,907,955,200 bytes free

K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\app\views\shared\>type menu.erb  
\<%= link\_to ‘Vendor’, :controller=\>‘vendors’,  
:action=\>‘index’ %\> &nbsp;  
\<%= link\_to ‘User’, :controller=\>‘users’,  
:action=\>‘index’ %\> &nbsp;

K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\app\views\shared\>type  
menu.html.erb  
\<%= link\_to ‘Vendor’, :controller=\>‘vendors’,  
:action=\>‘index’ %\> &nbsp;  
\<%= link\_to ‘User’, :controller=\>‘users’,  
:action=\>‘index’ %\> &nbsp;

K:\_Projects\Ruby\_Rails\_Apps\_EIMS\RTS\app\views\shared\>

I know the message said “menu.erb” but I thought it might not be up-to-  
date with Rails 2.3.5, which I running, along with Ruby 1.8.6.

If you’re up to another look at this, I’d be in your debt.

Best wishes,  
Richard
