# Script.aculos.us and the in\_place\_editor

**URL:** <https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799>\
**Category:** Rails\
**Created:** [January 19, 2006, 6:11am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799 "2006-01-19T06:11:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 19, 2006, 6:11am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/1 "2006-01-19T06:11:02Z")

</div>

Hi there,

I’ve been trying incorporate the in\_place\_editor, but have had no luck  
so far. I read the Ajax.In Place editor wiki on [script.aculos.us](http://script.aculos.us) which  
was informing, but still left me wondering about a few things.

Here’s what I’m trying to do. A user has a profile page which lists  
their name, age, homepage, etc… There is no form on this page…  
it’s just regular text. Here’s a snippet:

Name:\<%= @user.first\_name %\>&nbsp;\<%= @user.last\_name %\>

```
<p>
	<div class="profile_details_container">
		<span class="profile_title">Email:</span>
		<span class="profile_info"><%= @user.email %></span>
	</div>
</p>

```

…etc…

When a user clicks on the text inside the   
tags I would like a text box to pop up in it’s place which allows the  
user to edit their value.

I got the in place editor to show up by doing the following:

Age: \<%= @profile.age %\> \<%= in\_place\_editor('@profile.age' + @profile.id.to\_s, :url =\> {:action =\> 'ajax\_update'}, )%\> 

```
</div>

```

At the top of my profile controller I placed the following:

in\_place\_edit\_for :profile, :age

This is where I have a question. How do would I actually go about  
saving the new value that was inputted into the text box that popped  
up? I have the following in the ‘ajax\_update’ action. This obviously  
doesn’t work!

def ajax\_update  
@profile = params[:value]  
render :layout =\> false, :inline =\> “\<%= @profile.age ) %\>”  
end

Am I close? Is there a better way to accomplish what I’m trying to do?

Thank you!  
-Dave H.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 19, 2006, 7:34am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/2 "2006-01-19T07:34:05Z")

</div>

Dave H. wrote:

> SNIP  
> \<%= @profile.age %\>  
> \<%= in\_place\_editor(’@profile.age’ + @profile.id.to\_s, :url =\>  
> {:action =\> ‘ajax\_update’}, )%\>

I think you will find in\_place\_editor\_field more to your liking here.  
Using age as an example, replace BOTH lines above with this:

\<%= in\_place\_editor\_field(:profile, :age) %\>

Rails will create a static text object that when clicked, becomes a text  
box. When the changes are saved, rails uses a dynamic action, you don’t  
need to write anything in your controller! 🙂

You can also add options for the the button text and such just as you  
can with in\_place\_editor…

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 19, 2006, 8:17am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/3 "2006-01-19T08:17:40Z")

</div>

Brad D. wrote:

> I think you will find in\_place\_editor\_field more to your liking here.  
> Using age as an example, replace BOTH lines above with this:
> 
> \<%= in\_place\_editor\_field(:profile, :age) %\>

Very, VERY cool, but in a partial, you don’t have an instance variable.  
I created one, but it’s a workaround. Is there a more general solution?

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 19, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/4 "2006-01-19T15:17:27Z")

</div>

Brad,

That’s perfect! I can’t believe I overlooked such a simple function!

Thanks you,  
Dave

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [January 19, 2006, 10:39am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/5 "2006-01-19T10:39:27Z")

</div>

I am using following solution.

\<iterate over all object (a) and all languages (l)\>  
\<%= a.send  
(“name\_#{l.short\_name}”) %\>  
\<%= in\_place\_editor(“attribute\_#{a.id}\_#{l.short\_name}”,  
:url=\>url\_for(:action=\>‘update\_attribute\_text’),  
:with=\>“‘language=#{l.short\_name}&id=#{a.id}&value=’ +  
escape(value)”) %\>  
\</close iteration loop\>

It is code from my current project and it working pretty neat  
Also controller code

def update\_attribute\_text  
a = Attribute.find(@params[:id])  
a.send(“name\_#{@params[:language]}=”, @params[:value])  
a.save!  
render :text =\> @params[:value]  
end

That’s it. As you see there is no any instance variables.

You should only look to [http://dev.rubyonrails.org/ticket/3529](http://dev.rubyonrails.org/ticket/3529) to fix  
bug in  
rails with inplace\_editor function.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [October 28, 2006, 9:48am UTC](https://www.ruby-forum.com/t/script-aculos-us-and-the-in-place-editor/52799/6 "2006-10-28T09:48:15Z")

</div>

how can i start or use the in\_place\_editor of ruby with a given specific  
item to input and when i click the the button it should display the  
information of the whole item…plz help me
