Need to DRY views for a global menu

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 %>

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.


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)

Craig


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

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

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.

----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.

OK Craig,

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

Best wishes,
Richard

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’ %>  
<%= link_to ‘User’, :controller=>‘users’,
:action=>‘index’ %>  

K:_Projects\Ruby_Rails_Apps_EIMS\RTS\app\views\shared>type
menu.html.erb
<%= link_to ‘Vendor’, :controller=>‘vendors’,
:action=>‘index’ %>  
<%= link_to ‘User’, :controller=>‘users’,
:action=>‘index’ %>  

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs