Rails newbie: why is my partial template not rendering?

Hi there,

I wanted to be a good Rails programmer, and use a shared partial
template for
common view logic (in this case, displaying information about users).

The view code that uses the render() call looks (something) like this:

<p>And now, the hat sizes of our users... </p>
<% render(:partial => "shared/user", :locals => { :user => @user })
-%>

..and my app/views/shared/user.rthml file looks like:

<p><%=h user.name -%></p><p><%=h user.hat_size -%></p>

Now, the files are named and located where they should be as far as I
can tell,
but I never see my users' names or hat sizes rendered. Viewing the HTML
source
of the resulting page shows.. nothing at all. Nothing is rendered,
maybe not even
whitespace!

Any ideas as to what's going on? What am I missing? I'm stumped.

Thx in advance,
-- Dan C.

You may get better, faster answers asking rails questions on the rails mailing list:

http://lists.rubyonrails.org/mailman/listinfo/rails

···

dan.caugherty@gmail.com wrote:

Hi there,

I wanted to be a good Rails programmer, and use a shared partial
template for
common view logic (in this case, displaying information about users).

--
James Britt

Hi there,

I wanted to be a good Rails programmer, and use a shared partial
template for
common view logic (in this case, displaying information about users).

The view code that uses the render() call looks (something) like this:

<p>And now, the hat sizes of our users... </p>
<% render(:partial => "shared/user", :locals => { :user => @user })
-%>

..and my app/views/shared/user.rthml file looks like:

<p><%=h user.name -%></p><p><%=h user.hat_size -%></p>

Now, the files are named and located where they should be as far as I
can tell,

No they aren't :wink:

it has to be app/views/shared/_user.rhtml to be a partial.

···

On Aug 31, 2006, at 10:20 PM, dan.caugherty@gmail.com wrote:

but I never see my users' names or hat sizes rendered. Viewing the HTML
source
of the resulting page shows.. nothing at all. Nothing is rendered,
maybe not even
whitespace!

Any ideas as to what's going on? What am I missing? I'm stumped.

Thx in advance,
-- Dan C.

The view code that uses the render() call looks (something) like this:

<p>And now, the hat sizes of our users... </p>
<% render(:partial => "shared/user", :locals => { :user => @user })
-%>

Ah, I've done this many many times... You're missing a "="

<% render ...

should be
<%= render ...

And the partial file name needs to start with an underscore.

Cheers,
Max

The Rails list recently moved to:
http://groups.google.com/group/rubyonrails-talk

···

On 8/31/06, James Britt <james.britt@gmail.com> wrote:

You may get better, faster answers asking rails questions on the rails
mailing list:

http://lists.rubyonrails.org/mailman/listinfo/rails

--
Greg Donald
http://destiney.com/

If you're going to answer a Rails question send the answer to the Rails list and CC the author. Rails has its own mailing list full of helpful smiling people.

···

On Aug 31, 2006, at 8:30 PM, Logan Capaldo wrote:

On Aug 31, 2006, at 10:20 PM, dan.caugherty@gmail.com wrote:

[rails question]

[rails answer]

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

The rails list, I think, has changed to using a Google Group.

-austin

···

On 8/31/06, James Britt <james.britt@gmail.com> wrote:

You may get better, faster answers asking rails questions on the rails
mailing list:

http://lists.rubyonrails.org/mailman/listinfo/rails

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca

Both Logan's and Max's answers are right on the money. That should set
you up just fine.

The Rails list recently moved to:
http://groups.google.com/group/rubyonrails-talk

I'd definitely join this mailing list as it will be much more focused
on Rails. (And, besides, who likes hearing messages about posting
questions on the other list anyhow? Hehehe.)

By the by, did you know you don't have to put the ()s in the message passing?

<%= render(:partial => "shared/user", :locals => { :user => @user }) -%>

could be

<%= render :partial => "shared/user", :locals => { :user => @user } -%>

which is a bit cleaner in my opinion. (That whole signal verses noise thing.)

Cheers,

M.T.

P.S. -- Come to think of it, I'm not sure if you have to specify
"shared/_user" or just "shared/user" as your partial template. Hmm.

Greg Donald wrote:

···

On 8/31/06, James Britt <james.britt@gmail.com> wrote:

You may get better, faster answers asking rails questions on the rails
mailing list:

http://lists.rubyonrails.org/mailman/listinfo/rails

The Rails list recently moved to:
http://groups.google.com/group/rubyonrails-talk

Ah. Thanks.

Too bad lists.rubyonrails.org doesn't have this info.

--
James Britt

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

Thank you everyone for showing me the error of my ways
(the missing =, and alerting me to the presence of the Rails group).

And yes, this topic does need to be in a FAQ somewhere. Argh!

Cheers,
-- Dan C.