Script.aculos.us and the in_place_editor

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 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 %> <%= @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.

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! :slight_smile:

You can also add options for the the button text and such just as you
can with in_place_editor…

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?

Brad,

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

Thanks you,
Dave

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 to fix
bug in
rails with inplace_editor function.

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