# Probelm with partials

**URL:** <https://www.ruby-forum.com/t/probelm-with-partials/131969>\
**Category:** Rails\
**Created:** [March 14, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969 "2008-03-14T20:18:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/1 "2008-03-14T20:18:40Z")

</div>

I have this in my view:

# New client

\<%= error\_messages\_for :client %\>  
\<%= error\_messages\_for :entity %\>

\<% form\_for(@client) do |f| %\>

\<% render :partial =\> “entities/entity\_fields\_for”, :object =\>  
“@entity” %\>

**Client status**  
 \<%= f.text\_field :client\_status %\>

**Client credit policy**  
 \<%= f.text\_field :client\_credit\_policy %\>

...

I have this in entities/\_entity\_fields\_for.html.erb

### Entity Header
\<% fields\_for(@entity) do |e| %\> 

**Entity Name**  
 \<%= e.text\_field :entity\_name %\>

```
<p>
  <b>Entity Legal Name</b><br />
  <%= e.text_field :entity_legal_name %>
</p>

<p>
  <b>Entity Legal Form</b><br />
  <%= e.text_field :entity_legal_form %>
</p>

```

\<% end %\>

When I try and add a new client I only see this:

New client  
XXXXXXXXXXXXXXXXXXXXXXXX

Client status  
XXXXXXXXXXXXXXXXXXXXXXXX

Client credit policy  
XXXXXXXXXXXXXXXXXXXXXXXX

Client credit terms  
XXXXXXXXXXXXXXXXXXXXXXXX

Effective from  
XXXX XXXXXXXX XX

Superseded after  
XXXX XXXXXXXX XX

Back

and in the log I see this:

Processing ClientsController#new (for 127.0.0.1 at 2008-03-14 15:13:12)  
[GET]  
Session ID:  
BAh7BzoMY3NyZl9pZCIlODdiM2M2YWNlZWVmZTFmYTgzMDk5MzQ2ODI0MWI2%0AYzAiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D–183ba94d00e732557171e89ef1b916a18f66701d  
Parameters: {“action”=\>“new”, “controller”=\>“clients”}  
Rendering template within layouts/clients  
Rendering clients/new  
Rendered entities/\_entity\_fields\_for (0.00370)  
Completed in 0.05382 (18 reqs/sec) | Rendering: 0.01708 (31%) | DB:  
0.00000 (0%)

So what obvious ( to others) thing am I leaving out or not doing with  
respect to displaying the partial? If the code that is in the partial  
is left in the new template then it displays as expected.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/2 "2008-03-14T20:25:29Z")

</div>

one error that look obvious is that:  
\<% render :partial =\> “entities/entity\_fields\_for”, :object =\>  
“@entity” %\>

should be:  
\<% render :partial =\> “entities/entity\_fields\_for”, :object =\>  
@entity %\>

without those quotes arount @entity

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:33pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/3 "2008-03-14T20:33:16Z")

</div>

Thorsten M. wrote:

> one error that look obvious is that:  
> \<% render :partial =\> “entities/entity\_fields\_for”, :object =\>  
> “@entity” %\>
> 
> should be:  
> \<% render :partial =\> “entities/entity\_fields\_for”, :object =\>  
> @entity %\>
> 
> without those quotes arount @entity

The presence or absence of “” around the instance variable does not  
change the observed behaviour. The fields are still left un-rendered.  
In any case, there is a constant present in the partial,

### Entity Header
, which is not displayed either and whose display is  
independent of any values passed to the partial template. The problem  
is that the log says that the partial is being rendered and yet none of  
its contents, not even the label and heading text, are present in the  
resulting html document sent to my browser.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:37pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/4 "2008-03-14T20:37:18Z")

</div>

right, but a closer look:

use \<%= %\> instead of \<% %\>

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/5 "2008-03-14T20:49:42Z")

</div>

Thorsten M. wrote:

> right, but a closer look:
> 
> use \<%= %\> instead of \<% %\>

Where? The partial uses \<%= %\> already. What else needs to have the  
ruby generated code put into the document?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/6 "2008-03-14T20:51:44Z")

</div>

James B. wrote:

> Thorsten M. wrote:
> 
> > right, but a closer look:
> > 
> > use \<%= %\> instead of \<% %\>
> 
> Where? The partial uses \<%= %\> already. What else needs to have the  
> ruby generated code put into the document?

Got it. Thanks.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 14, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/probelm-with-partials/131969/7 "2008-03-14T23:55:14Z")

</div>

On Mar 14, 2008, at 3:18 PM, James B. wrote:

> \<%= render :partial =\> “entities/entity\_fields\_for”, :object =\>
> 
> ...
> 
> I have this in entities/\_entity\_fields\_for.html.erb
> 
> ### Entity Header
> \<% fields\_for(@entity) do |e| %\>

fields\_for(entity\_fields\_for) do |e|

By using :object, you’re telling the partial which object the local  
that is the name of the partial (i.e., entity\_fields\_for) refers.

> XXXX XXXXXXXX XX  
> [GET]
> 
> So what obvious ( to others) thing am I leaving out or not doing with  
> respect to displaying the partial? If the code that is in the partial  
> is left in the new template then it displays as expected.

The presence or lack or quotes in the render line have no effect  
because you specifically used @entity within the partial anyway and  
never used the local variable that you set up with :object (which gets  
the name of the partial every time).

Thorsten’s comments about \<% vs. \<%= are important, too, of course.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
