Forum: Ruby on Rails Nooby partials / component problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9ac2db57875d22b54bcd9618bb171b21?d=identicon&s=25 Steven Rogers (srogers)
on 2006-05-21 21:56
(Received via mailing list)
I'm stumped on what seems like should be a fairly easy thing, so I
hope someone can point out my error.

I wanted to show a few things on every page, so I added an
application level template in "layouts". I added my styles in there,
and put the controller name and action name into the TITLE tag for my
own reference. So far so good - works like expected. Then I wanted to
show some info looked up in the DB based on session variables, so I
added a method to do that on one of my controllers, and added

<% render_component :controller => 'user', :action => 'identity' %>

to my application level template. Now when I call this action
directly via http://localhost:3000/user/identity I get just what I
expect, but nothing shows up via the template reference. I know its
being called, because if I introduce an error into that action, the
template gets that error, but when it works - nothing comes out in
the web page from that component. The rest of the template continues
to work the same as always - styles in HEAD, the content_for_layout,
etc. are all there like normal - its just like the render_component
has no effect unless there's an error in it.

So then I decided to try using a partial, since it seemed a little
more "foolproof", and somewhat  based on the mention in AWDR v2 that
components are not as favored. So I added:

<% render :partial => 'shared/footer' %>

to my application level template and just added some plain ole hard-
coded HTML in views/shared/_footer.rhtml

Weirdly, nothing comes out in my template. It seems that the file
_footer.rhtml is being referenced, because I get the dreaded white
screen if the file isn't there, and if I put a Ruby error into the
partial, I get that error when I reference the page. However, just
like the component above, so long as its working, its like it doesn't
exist.

So what the heck am I missing here?  I've been over p. 116-120 in
AWDR about a zillion times. It seems pretty simple, yet I'm stumped.

I'm using:
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0]
Rails 1.1.2
org.radrails.rails_feature, Version: 0.6.3

Thanks,
Steve
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-05-22 03:38
(Received via mailing list)
Steven Rogers wrote:

> I'm stumped on what seems like should be a fairly easy thing, so I hope
> someone can point out my error.
>
> I added a method to
> do that on one of my controllers, and added
>
> <% render_component :controller => 'user', :action => 'identity' %>
>
> to my application level template.

This should be:

<%= render_component :controller => 'user', :action => 'identity' %>

note the "="

If you use the <% %> form, the code inside is executed, but not
displayed. If you use <%= %> then the result of executing the code is
added to the output string.

--

Ray
This topic is locked and can not be replied to.