# Update element after in\_place\_editor?

**URL:** <https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016>\
**Category:** Rails\
**Created:** [September 19, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016 "2007-09-19T19:26:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [September 19, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016/1 "2007-09-19T19:26:08Z")

</div>

Hi, I’m kicking my brains around the forecourt, this things is  
absolutely driving me to insanity.

Here’s the problem, I’m using the in\_place\_editor\_field to edit a  
reminder’s title and save it, all going good but said item isn’t getting  
updated with the new value; record is but not the view.

## here’s the reminder controller code…

def list  
@reminders = Reminder.find(:all)  
end

def set\_item\_title  
@reminder = Reminder.find(params[:id])  
@reminder.update\_attributes(:title =\> params[:value])

```
@reminders = Reminder.find(params[:id])
render :update do |page|
  page.replace_html('item_#params[:id]', :partial => 'item',

```

:collection =\> @reminders)  
end  
#render :nothing =\> true  
#replace\_html ‘item\_’ + @reminder.id, :partial =\> ‘item’, :object =\>  
@reminder  
end

## in the items partial…

\<% for @item in @reminders %\>  
\<% if @item.user\_id == self.current\_user.id %\>  
\<%= render :partial =\> ‘item’ %\>  
\<% end %\>  
\<% end %\>

## in the item partial…
- \<%= in\_place\_editor\_field :item, :title %\>  
 \<%= @item.date.strftime("%a %d %b %y, %I:%M %p") %\>  

\<%= link\_to ‘[Edit]’, :action =\> ‘edit’, :id =\> @item %\>  
\<%= link\_to ‘[Destroy]’, { :action =\> ‘destroy’, :id =\> @item.id },  
:confirm =\> ‘Are you sure?’, :method =\> :post %\>

any idea where i’m going wrong, doing my nut in.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [September 19, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016/2 "2007-09-19T19:45:35Z")

</div>

Bingo!

render :update do |page|  
page.replace ‘item\_’ \<\< params[:id], :partial =\> ‘item’, :object =\>  
@item  
end

ok, it’s not pretty and i don’t know why + or #params[:id] wouldn’t work  
in the string.

if anyone’s got any ideas that’d be great

gonna go home to an ice cold beer now, ughh…

John G. wrote:

> Hi, I’m kicking my brains around the forecourt, this things is  
> absolutely driving me to insanity.
> 
> Here’s the problem, I’m using the in\_place\_editor\_field to edit a  
> reminder’s title and save it, all going good but said item isn’t getting  
> updated with the new value; record is but not the view.
> 
> ## here’s the reminder controller code…
> 
> def list  
> @reminders = Reminder.find(:all)  
> end
> 
> def set\_item\_title  
> @reminder = Reminder.find(params[:id])  
> @reminder.update\_attributes(:title =\> params[:value])
> 
> ```
> @reminders = Reminder.find(params[:id])
> render :update do |page|
> page.replace_html('item_#params[:id]', :partial => 'item',
> 
> ```
> 
> :collection =\> @reminders)  
> end  
> #render :nothing =\> true  
> #replace\_html ‘item\_’ + @reminder.id, :partial =\> ‘item’, :object =\>  
> @reminder  
> end
> 
> ## in the items partial…
> 
> \<% for @item in @reminders %\>  
> \<% if @item.user\_id == self.current\_user.id %\>  
> \<%= render :partial =\> ‘item’ %\>  
> \<% end %\>  
> \<% end %\>
> 
> ## in the item partial…
> - \<%= in\_place\_editor\_field :item, :title %\>  
> \<%= @item.date.strftime("%a %d %b %y, %I:%M %p") %\>  
> 
> \<%= link\_to ‘[Edit]’, :action =\> ‘edit’, :id =\> @item %\>  
> \<%= link\_to ‘[Destroy]’, { :action =\> ‘destroy’, :id =\> @item.id },  
> :confirm =\> ‘Are you sure?’, :method =\> :post %\>
> 
> any idea where i’m going wrong, doing my nut in.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [September 19, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016/3 "2007-09-19T20:53:59Z")

</div>

On 9/19/07, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if anyone’s got any ideas that’d be great

Rails has a helper that generates the controller method for you. You  
would add:

in\_place\_edit\_for :item, :title

Also, in\_place\_editor\_field generates an Ajax.Updater, so the render  
:update is not really appropriate. From the docs for in\_place\_editor,

“…the action on the server should process the value and return the  
updated value in the body of the reponse”

Using in\_place\_edit\_for in your controller takes care of that for you.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [September 20, 2007, 11:29am UTC](https://www.ruby-forum.com/t/update-element-after-in-place-editor/115016/4 "2007-09-20T11:29:22Z")

</div>

tried using that, wouldn’t work,

i’ll have a bash at it again next time i’m working on it, right now i’m  
just glad it works.

but thanks Bob,

appreciate it,

😉

Bob S. wrote:

> On 9/19/07, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > if anyone’s got any ideas that’d be great
> 
> Rails has a helper that generates the controller method for you. You  
> would add:
> 
> in\_place\_edit\_for :item, :title
> 
> Also, in\_place\_editor\_field generates an Ajax.Updater, so the render  
> :update is not really appropriate. From the docs for in\_place\_editor,
> 
> “…the action on the server should process the value and return the  
> updated value in the body of the reponse”
> 
> Using in\_place\_edit\_for in your controller takes care of that for you.
