Forum: Ruby on Rails script.aculos.us and the in_place_editor

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.
12be02204a4bcaeec2c6c369fe53a45b?d=identicon&s=25 Dave Hoefler (Guest)
on 2006-01-19 06: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 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:

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

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

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


	</div>
</p>

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 Hoefler
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-01-19 07:34
Dave Hoefler 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....
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-01-19 08:17
Brad Daily 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?
1c46e952a61c99d9eae4f21037a088fd?d=identicon&s=25 Anatol Pomozov (Guest)
on 2006-01-19 10:39
(Received via mailing list)
I am using following solution.

<iterate over all object (a) and all languages (l)>
        <span id='<%= "attribute_#{a.id}_#{l.short_name}" %>'><%= a.send
("name_#{l.short_name}") %></span>
        <%= 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.
12be02204a4bcaeec2c6c369fe53a45b?d=identicon&s=25 Dave Hoefler (Guest)
on 2006-01-19 15:17
(Received via mailing list)
Brad,

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

Thanks you,
Dave
9bef48431deb81ada8cbc688e7e7cbad?d=identicon&s=25 Joseph (Guest)
on 2006-10-28 09: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.