# Passing in each item.id in a method

**URL:** <https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439>\
**Category:** Rails\
**Created:** [December 4, 2005, 6:35pm UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439 "2005-12-04T18:35:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jtei](https://www.ruby-forum.com/u/jtei)\
**Post date:** [December 4, 2005, 6:35pm UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439/1 "2005-12-04T18:35:57Z")

</div>

Hi everyone, I am trying to implement the in\_place\_editor method and am  
trying to pass in each item.id as the elementID argument. So I’m trying  
to do something like this, \<% in\_place\_editor(‘title\_\<%=item.id%\>’,  
:rows =\> “1”,…) %\> But that doesn’t work. Here is my code,  
[http://rafb.net/paste/results/K5yFSG20.html](http://rafb.net/paste/results/K5yFSG20.html) My goal here is to be able  
to make this in\_place\_editor work for each of the items in the list.  
Any ideas??

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jtei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jtei](https://www.ruby-forum.com/u/jtei)\
**Post date:** [December 4, 2005, 10:18pm UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439/2 "2005-12-04T22:18:23Z")

</div>

On 12/4/05, Jordan I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi everyone, I am trying to implement the in\_place\_editor method and am  
> trying to pass in each item.id as the elementID argument. So I’m trying  
> to do something like this, \<% in\_place\_editor(‘title\_\<%=item.id%\>’,  
> :rows =\> “1”,…) %\> But that doesn’t work.

\<% in\_place\_editor(“title\_#{item.id}”, :rows =\> “1”,…) %\>

---

<div class="post-metadata">

**Author:** ![jtei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jtei](https://www.ruby-forum.com/u/jtei)\
**Post date:** [December 4, 2005, 10:41pm UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439/3 "2005-12-04T22:41:27Z")

</div>

Hi Jeremy, thanks for the reply. I did what you posted and I am getting  
an error message saying ‘item’ is undefined. However, it works for  
item.id earlier in the code? Any ideas? Sorry I am a noob at rails.  
Here is my updated code with error message pasted in below:

[http://rafb.net/paste/results/T4b8ew63.html](http://rafb.net/paste/results/T4b8ew63.html)

Thanks!

jeremyevans0 wrote:

> On 12/4/05, Jordan I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi everyone, I am trying to implement the in\_place\_editor method and am  
> > trying to pass in each item.id as the elementID argument. So I’m trying  
> > to do something like this, \<% in\_place\_editor(‘title\_\<%=item.id%\>’,  
> > :rows =\> “1”,…) %\> But that doesn’t work.
> 
> \<% in\_place\_editor(“title\_#{item.id}”, :rows =\> “1”,…) %\>

---

<div class="post-metadata">

**Author:** ![jtei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jtei](https://www.ruby-forum.com/u/jtei)\
**Post date:** [December 5, 2005, 2:13am UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439/4 "2005-12-05T02:13:30Z")

</div>

Ah you are right, it worked! Thanks for the help and the link!

jeremyevans0 wrote:

> On 12/4/05, Jordan I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi Jeremy, thanks for the reply. I did what you posted and I am getting  
> > an error message saying ‘item’ is undefined. However, it works for  
> > item.id earlier in the code? Any ideas? Sorry I am a noob at rails.  
> > Here is my updated code with error message pasted in below:
> > 
> > [http://rafb.net/paste/results/T4b8ew63.html](http://rafb.net/paste/results/T4b8ew63.html)
> 
> item is defined as a local block variable earlier on in the code,  
> that’s why it works there. item is undefined when you use it later.  
> You may be able to get what you want by moving the sortable\_element  
> and in\_place\_editor inside the block.
> 
> In any case, I’d pick up a good book on Ruby before you go much  
> further. There’s a free online one at  
> [http://www.rubycentral.com/book/](http://www.rubycentral.com/book/). It will explain variable scope  
> among other important issues.

---

<div class="post-metadata">

**Author:** ![jtei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jtei](https://www.ruby-forum.com/u/jtei)\
**Post date:** [December 4, 2005, 10:51pm UTC](https://www.ruby-forum.com/t/passing-in-each-item-id-in-a-method/49439/5 "2005-12-04T22:51:11Z")

</div>

On 12/4/05, Jordan I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Jeremy, thanks for the reply. I did what you posted and I am getting  
> an error message saying ‘item’ is undefined. However, it works for  
> item.id earlier in the code? Any ideas? Sorry I am a noob at rails.  
> Here is my updated code with error message pasted in below:
> 
> [http://rafb.net/paste/results/T4b8ew63.html](http://rafb.net/paste/results/T4b8ew63.html)

item is defined as a local block variable earlier on in the code,  
that’s why it works there. item is undefined when you use it later.  
You may be able to get what you want by moving the sortable\_element  
and in\_place\_editor inside the block.

In any case, I’d pick up a good book on Ruby before you go much  
further. There’s a free online one at  
[http://www.rubycentral.com/book/](http://www.rubycentral.com/book/). It will explain variable scope  
among other important issues.
