Link to home
Start Free TrialLog in
Avatar of anki2584

asked on

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

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

# part of view showing search results
<%@people.each do |person|%>
<%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 controller
def updateattribute
  @person = Person.find(params[:id])
  i = params[:editorId]
  j = i.split("_")
  field_name = j.join("_")#Getting the field to be updated in field_name
  @person.update_attribute "#{field_name}", "#{params[:value]}"  
# 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 => } %></td>

Open in new window

Avatar of garpenlov

Try updating your rjs file to this.
# updateattribute.rjs
page.replace_html 'first_name', :partial=>'first_name', :object=>@person, :script=>true

Open in new window

Avatar of anki2584


Prorbably i see whtas going wrong but please suggest me how to correct it.
I have noticed that the program works fine if it is the first entry in the table.
Trying to update any other table row brings out this error and the output comes in the cell of the first row. This could be because i am using a div  while looping through a table and so the program does not know which cell is being updated.
I am not sure whether it will be possible to use the div in such manner.
Please suggest me how can i overcome this problem.
Avatar of wesgarrison
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. I found this out in the mean time the response was made. your answer was acccurate.