Forum: Ruby on Rails Passing in each item.id in a method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jordan I. (Guest)
on 2005-12-04 19:35
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  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!
jeremyevans0 (Guest)
on 2005-12-04 23:18
(Received via mailing list)
On 12/4/05, Jordan I. <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",.....) %>
Jordan I. (Guest)
on 2005-12-04 23:41
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

Thanks!

jeremyevans0 wrote:
> On 12/4/05, Jordan I. <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",.....) %>
jeremyevans0 (Guest)
on 2005-12-04 23:51
(Received via mailing list)
On 12/4/05, Jordan I. <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

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/.  It will explain variable scope
among other important issues.
Jordan I. (Guest)
on 2005-12-05 03:13
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> 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
>
> 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/.  It will explain variable scope
> among other important issues.
This topic is locked and can not be replied to.