unknown
September 1, 2006, 4:25am
1
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:
And now, the hat sizes of our users...
<% render(:partial => "shared/user", :locals => { :user => @user })
-%>
…and my app/views/shared/user.rthml file looks like:
<%=h user.name -%>
<%=h user.hat_size -%>
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.
unknown
September 1, 2006, 4:43am
2
[email protected] 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/listinfo/rails
unknown
September 1, 2006, 5:33am
3
On Aug 31, 2006, at 10:20 PM, [email protected] wrote:
<% render(:partial => “shared/user”, :locals => { :user => @user })
-%>
…and my app/views/shared/user.rthml file looks like:
<%=h user.name -%>
<%=h user.hat_size -%>
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.
unknown
September 1, 2006, 5:51am
4
The view code that uses the render() call looks (something) like this:
And now, the hat sizes of our users...
<% 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
unknown
September 1, 2006, 5:53am
5
On 8/31/06, James B. [email protected] 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
unknown
September 1, 2006, 7:30am
6
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.
unknown
September 1, 2006, 7:20am
7
On Aug 31, 2006, at 8:30 PM, Logan C. wrote:
On Aug 31, 2006, at 10:20 PM, [email protected] 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 H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com
unknown
September 1, 2006, 2:46pm
8
On 8/31/06, James B. [email protected] 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, I think, has changed to using a Google Group.
-austin
unknown
September 1, 2006, 12:41pm
9
Greg D. wrote:
On 8/31/06, James B. [email protected] 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 B.
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
unknown
September 1, 2006, 3:26pm
10
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.