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
%> <%@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
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.... -- Posted via http://www.ruby-forum.com/.
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? -- Posted via http://www.ruby-forum.com/.
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.
On 1/19/06, Steve Ross <cwdinfo@gmail.com> wrote:>
> 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?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
anatol (http://pomozov.info)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060119/60b23693/attachment.html
Brad, That''s perfect! I can''t believe I overlooked such a simple function! Thanks you, Dave On 1/19/06, Anatol Pomozov <anatol.pomozov@gmail.com> wrote:> 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. > > > On 1/19/06, Steve Ross <cwdinfo@gmail.com> wrote: > > 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? > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > anatol (http://pomozov.info) > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---