Customising 'show'

Newb here;

I feel like im cheating when i actually write to the list, but i’ve
been stuck on this for a while now and cant seem to find the answer in
tutorials… heres the simplified version of the problem

controller says:

def show
@exhibition = Exhibition.find(params[:id])
end

content says:

<% for exhibition in @exhibitions %>
<%= link_to ‘Details’,
{:action => ‘show’, :id => exhibition.id }, :class => ‘show’ %>
<% end %>

linked to show template code says:
<%= h(@exhibition.gallery) %>
<%= link_to ‘Back’, :action => ‘index’ %>

clicking the show link works: in that i get a page and the url has
/show/3 - so the model id has been parsed through…
however the exhibition.gallery isn’t showing up on the page. the back
link is working.

i’m sure i’ve missed something in the ‘show’ template, but i have no
idea what it is

thanks for your time…

rebecca cannon wrote:

however the exhibition.gallery isn’t showing up on the page. the back
link is working.

i’m sure i’ve missed something in the ‘show’ template, but i have no
idea what it is

Hi Rebecca,

Some things to try and questions.

  • If you do a “view source” is there anything there at all ?
  • Is gallery a string or an associated model?
  • If you put <%= @exhibition.id %> into your show template do you see
    that ? (or any other field)
  • Can you show us your Exhibition model code ?

Alan

Hi Rebecca,

rebecca cannon wrote:

{:action => ‘show’, :id => exhibition.id }, :class => ‘show’ %>
<% end %>

linked to show template code says:
<%= h(@exhibition.gallery) %>
<%= link_to ‘Back’, :action => ‘index’ %>

clicking the show link works: in that i get a page and the url has
/show/3 - so the model id has been parsed through…
however the exhibition.gallery isn’t showing up on the page. the back
link is working.

Have you checked the database (i.e., using something like MySQL-Front)
to
verify that the gallery column contains the content you expect?

Best regards,
Bill

Kevin O. wrote:

<%= link_to ‘Details’,
{:action => ‘show’, :id => exhibition.id }, :class => ‘show’ %>
<% end %>

the controller should be:

def show
@exhibitions = Exhibition.find(params[:id])
end

Note the plural form of exhibition.

_Kevin

I don’t think so. I think the index action (which we didn’t see) was
giving the plural, which was iterated over (in the first template) to
give the link to show. The show action (correctly) gave the singular.

Alan

<%= link_to ‘Details’,
{:action => ‘show’, :id => exhibition.id }, :class => ‘show’ %>
<% end %>

the controller should be:

def show
@exhibitions = Exhibition.find(params[:id])
end

Note the plural form of exhibition.

_Kevin

Alan F. wrote:

Note the plural form of exhibition.

_Kevin

I don’t think so. I think the index action (which we didn’t see) was
giving the plural, which was iterated over (in the first template) to
give the link to show. The show action (correctly) gave the singular.

Alan

At the risk of grossly overstepping by bounds as a Rails noob myself, I
think Kevin is at least partly right. Rebecca’s show method in the
controller is assigning to @exhibition (singular) and the use of .find
suggests to me that she’s lookup up a single exhibition by it’s id (3).
However, her view is calling @exhibitions (plural) in a for loop, which
implies multiple exhibitions in an array. Which is wrong depends on what
she expects to see on the page, a single exhibition, or a list of
several.


Jonathan M.
Web D.
WW IDEA
http://www.wwidea.org
929 SW Higgins Ave, Suite B
Missoula, MT 59803
406-542-3334

“Next time you get an email telling you
to forward it to everyone you know…
pretend you don’t know me.” ~ Anonymous

Jonathan M. wrote:

Rebecca’s show method in the
controller is assigning to @exhibition (singular) and the use of .find
suggests to me that she’s lookup up a single exhibition by it’s id (3).
However, her view is calling @exhibitions (plural) in a for loop, which
implies multiple exhibitions in an array. Which is wrong depends on what
she expects to see on the page, a single exhibition, or a list of
several.

It’s two different action/view combos. There’s an index action (which
we haven’t yet seen) which will do a @exhibitions =
Exhibition.find(:all). This leads to the index.rhtml file which has the
loop we have seen. The body of that loop sets up a show link for a
single exhibition. The show link triggers the show action (which we
have also seen) and that contains single find for the requested
exhibition. This in turns trigger the show.rhtml template (which again,
we have seen).

This is just basic, default, generated scaffolding.

The only thing thats different is specifying @exhibition.gallery
directly instead of the dynamic looping over columns that we normally
see in the show.rhtml file. That’s where the problem seems to be and I
think the singular/plural thing is clouding the issue.

Alan

Alan