[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails newbie: why is my partial template not rendering?

Dan Caugherty

9/1/2006 2:19:00 AM

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.

9 Answers

James Britt

9/1/2006 2:41:00 AM

0

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

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

http://lists.rubyonrails.org/mailman/list...

--
James Britt


Logan Capaldo

9/1/2006 3:31:00 AM

0


On Aug 31, 2006, at 10:20 PM, 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).
>
> 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 ;)

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

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


Greg Donald

9/1/2006 3:49:00 AM

0

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

The Rails list recently moved to:
http://groups.google.com/group/rubyon...



--
Greg Donald
http://des...

Max Muermann

9/1/2006 3:49:00 AM

0

> 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

Eric Hodel

9/1/2006 5:17:00 AM

0

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]

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.

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

http://trackmap.rob...



Matt Todd

9/1/2006 5:29:00 AM

0

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

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.

James Britt

9/1/2006 6:07:00 AM

0

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/list...
>
>
> The Rails list recently moved to:
> http://groups.google.com/group/rubyon...

Ah. Thanks.

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



--
James Britt

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys

Austin Ziegler

9/1/2006 12:46:00 PM

0

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

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

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Dan Caugherty

9/1/2006 1:24:00 PM

0

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.