Forum: Ruby on Rails and the in_place_editor

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave H. (Guest)
on 2006-01-19 07:11
(Received via mailing list)
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 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:

<div class="profile_fields">
		<div class="profile_details_container">
			<span class="profile_title">Name:</span>
			<span class="profile_info"><%= @user.first_name %>&nbsp;<%=
@user.last_name %></span>

		<div class="profile_details_container">
			<span class="profile_title">Email:</span>
			<span class="profile_info"><%= %></span>


When a user clicks on the text inside the <span class="profile_info">
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:

	<div class="profile_details_container">
		<span class="profile_title">Age:</span>
		<span class="profile_info" id="<%='@profile.age' +
			<%= @profile.age %>
			<%= in_place_editor('@profile.age' +, :url =>
{:action => 'ajax_update'}, )%>


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 ) %>"

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

Thank you!
-Dave H.
Brad D. (Guest)
on 2006-01-19 08:34
Dave H. wrote:
> 			<%= @profile.age %>
> 			<%= in_place_editor('@profile.age' +, :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....
Steve R. (Guest)
on 2006-01-19 09:17
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?
Anatol P. (Guest)
on 2006-01-19 11:39
(Received via mailing list)
I am using following solution.

<iterate over all object (a) and all languages (l)>
        <span id='<%= "attribute_#{}_#{l.short_name}" %>'><%= a.send
("name_#{l.short_name}") %></span>
        <%= in_place_editor("attribute_#{}_#{l.short_name}",
              :with=>"'language=#{l.short_name}&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])!
    render :text => @params[:value]

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

You should only look to to fix
bug in
rails with inplace_editor function.
Dave H. (Guest)
on 2006-01-19 16:17
(Received via mailing list)

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

Thanks you,
Joseph (Guest)
on 2006-10-28 11:48
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
This topic is locked and can not be replied to.