Advertisement

07.17.2008 at 02:29AM PDT, ID: 23572549
[x]
Attachment Details

Getting the raw javascript code instead of Value after doing replace_html in RJS

Asked by anki2584 in Ruby Scripting Language, JavaScript, Asynchronous Javascript and XML (AJAX)

Tags: Ruby on Rails and RJS, try { Element.update("first_name", "\n \u003Cspan class=\"in_place_editor_field\" id=\"copy_first_name_10115_in_place_editor\"\u003EAnkit Agarwal\u003C/span\u003E\u003Cscript type=\"text/javascript\"\

I am ttrying to Update a field on my search result page thorugh in_place_edit and then render a partial to display the updated contents. I am receving the following instead od the real value

try { Element.update("first_name", "\n \u003Cspan class=\"in_place_editor_field\" id=\"copy_first_name_10115_in_place_editor\"\u003EAnkit Agarwal\u003C/span\u003E\u003Cscript type=\"text/javascript\"\

P.S. If i refresh the page manually  i get the correct Values as updated on the page.

Am attaching the code for the 4 files required to implement
1. The list of search results (view)
2. The controller contating the definition updateattribute
3. The updateattribute.rjs
4. _first_name.html.erb partial
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
# part of view showing search results
<table> 
<%@people.each do |person|%>
<tr>
 
<%if params[:first_name]="1"%><div id="first_name"><td><%unless person.first_name.blank?%>
 <%=@copyofperson = person; in_place_editor_field :copyofperson, :first_name, {}, :url => { :controller => 'person', :action => 'updateattribute', :id => person.id } %>
<%end%></td></div><%end%>
 
.
.
.
</tr>
<%end%>
</table>
 
#person controller
def updateattribute
  @person = Person.find(params[:id])
  i = params[:editorId]
  j = i.split("_")
  j.pop
  j.pop
  j.pop
  j.pop
  j.delete_at(0)
  field_name = j.join("_")#Getting the field to be updated in field_name
 
  @person.update_attribute "#{field_name}", "#{params[:value]}"  
 
end
 
 
# updateattribute.rjs
page.replace_html 'first_name', :partial=>'first_name', :object=>@person
 
 
 
# _first_name.html.erb
 
<div class ="first_name">
<td><%=@copyofperson = @person; in_place_editor_field :copyofperson, :first_name, {}, :url => { :controller => 'person', :action => 'updateattribute', :id => @person.id } %></td>
</div>
[+][-]07.18.2008 at 03:38PM PDT, ID: 22040412

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2008 at 11:10PM PDT, ID: 22041520

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 09:52PM PDT, ID: 22117578

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Ruby Scripting Language, JavaScript, Asynchronous Javascript and XML (AJAX)
Tags: Ruby on Rails and RJS, try { Element.update("first_name", "\n \u003Cspan class=\"in_place_editor_field\" id=\"copy_first_name_10115_in_place_editor\"\u003EAnkit Agarwal\u003C/span\u003E\u003Cscript type=\"text/javascript\"\
Sign Up Now!
Solution Provided By: wesgarrison
Participating Experts: 2
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628