# Partials issue

**URL:** <https://www.ruby-forum.com/t/partials-issue/195366>\
**Category:** Rails\
**Created:** [September 22, 2010, 8:43am UTC](https://www.ruby-forum.com/t/partials-issue/195366 "2010-09-22T08:43:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 8:43am UTC](https://www.ruby-forum.com/t/partials-issue/195366/1 "2010-09-22T08:43:51Z")

</div>

I’m following an example in the “Head First Rails” book regarding  
partials.

The book seems to be using a version prior Rails 3.0.0, which I’m using.

I’m having a small issue here.

There is a “new.html.erb” for “Seats” which will be created as a partial  
to be included in the “show.html.erb” page of “flights”.

So, the book mentions to copy: app/views/seats/new.html.erb and paste it  
to app/views/flights/\_new\_seat.html.erb

But, I’m using Rails 3.0.0, and you know that “new.html.erb” for “Seats”  
looks something like this:

# New seat

\<%= render ‘form’ %\>

\<%= link\_to ‘Back’, seats\_path %\>

So, there is a \_form.html.erb created automatically.

What did I do?

I copied the code above and inserted it as required in  
app/views/flights/\_new\_seat.html.erb and removing the last line.

Now came the problem when the book mentions that we make @seat in  
app/views/flights/\_new\_seat.html.erb a LOCAL variable, as follows:

\<% form\_for(seat) do | f| % \>

But, where is: \<% form\_for(@seat) do | f| % \> in my case?

It is in \_form.html.erb

And, here is a part of \_form.html.erb (Notice @seat)

\<%= form\_for(@seat) do |f| %\>  
\<% if @seat.errors.any? %\>

  

## \<%= pluralize(@seat.errors.count, “error”) %\> prohibited this seat from being saved:

```
  <ul>
  <% @seat.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>

```

\<% end %\>

If I change @seat here to “seat”, this I think will affect  
“new.html.erb” and “edit.html.erb” of “seats”.

So, I copied the file to app/views/flights/\_form\_seat.html.erb and  
changed ALL @seat to “seat”.

After running the application I get the following:

undefined local variable or method `seat’ for  
#\<#Class:0x4de6b78:0x4e5b9b0\>

Extracted source (around line #1):

1: \<%= form\_for(seat) do |f| %\>  
2: \<% if seat.errors.any? %\>  
3:

  
4: 
## \<%= pluralize(seat.errors.count, “error”) %\> prohibited this seat from being saved:

How can I solve this issue?

Sorry for my long question, but had to clarify the point.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 8:47am UTC](https://www.ruby-forum.com/t/partials-issue/195366/2 "2010-09-22T08:47:49Z")

</div>

I forgot to mention:

This is how I made the render in app/views/flights/\_new\_seat.html.erb

\<%= render ‘form\_seat’, :locals =\> {:seat =\> Seat.new} %\>

Provided again, I’m using Rails 3.0.0

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 8:50am UTC](https://www.ruby-forum.com/t/partials-issue/195366/3 "2010-09-22T08:50:53Z")

</div>

pass the seat variable with your render call something like this,

\<%= render ‘form’, :locals =\> { :seat =\> @seat } %\>

–  
Regards,

T.Veerasundaravel.  
[http://tinyurl.com/25vma7h](http://tinyurl.com/25vma7h)  
@veerasundaravel

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 8:57am UTC](https://www.ruby-forum.com/t/partials-issue/195366/4 "2010-09-22T08:57:07Z")

</div>

Veera S. wrote:

> pass the seat variable with your render call something like this,
> 
> \<%= render ‘form’, :locals =\> { :seat =\> @seat } %\>
> 
> –  
> Regards,
> 
> T.Veerasundaravel.  
> [http://tinyurl.com/25vma7h](http://tinyurl.com/25vma7h)  
> @veerasundaravel

Thanks @Veera.

It actually worked when I inserted :partial =\> explicitly like this:

\<%= render :partial =\> ‘form\_seat’, :locals =\> {:seat =\> Seat.new } %\>

When I tried your solution:

\<%= render ‘form\_seat’, :locals =\> {:seat =\> @seat } %\>

I got the following:

undefined local variable or method `seat’ for  
#\<#Class:0x515bb78:0x515aa50\>

Extracted source (around line #1):

1: \<%= form\_for(seat) do |f| %\>  
2: \<% if seat.errors.any? %\>  
3:

  
4: 
## \<%= pluralize(seat.errors.count, “error”) %\> prohibited this seat from being saved:

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 11:09am UTC](https://www.ruby-forum.com/t/partials-issue/195366/5 "2010-09-22T11:09:07Z")

</div>

tundrax wrote:

> Try using \<%= render ‘form’, :seat =\> @seat %\> without locals.

Thanks @tundrax. I’ll try that soon.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 9:15am UTC](https://www.ruby-forum.com/t/partials-issue/195366/6 "2010-09-22T09:15:09Z")

</div>

Try using \<%= render ‘form’, :seat =\> @seat %\> without locals.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 6:57pm UTC](https://www.ruby-forum.com/t/partials-issue/195366/7 "2010-09-22T18:57:49Z")

</div>

@Marnen. The issue was solved.

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 22, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/partials-issue/195366/8 "2010-09-22T18:40:22Z")

</div>

Abder-Rahman A. wrote:

> I’m following an example in the “Head First Rails” book regarding  
> partials.
> 
> The book seems to be using a version prior Rails 3.0.0, which I’m using.

[…]

Then you’re setting yourself up for trouble. If you’re learning Rails  
3, find a Rails 3 book.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
