I am trying to Update a field on my search result page through
in_place_edit and then render a partial to display the updated contents.
I am receving the following instead of the real value which is “John
Wright”
try { Element.update(“first_name”, "\n \u003Cspan
class=“in_place_editor_field”
id=“copy_first_name_10115_in_place_editor”\u003EJohn
Wright\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.
Following is my the code for the 4 files required to implement
- The list of search results (view)
- The controller contating the definition updateattribute
- The updateattribute.rjs
- _first_name.html.erb partial
part of view showing search results
<%unless person.first_name.blank?%> <%[email protected] = person; in_place_editor_field :copyofperson, :first_name, {}, :url => { :controller => ‘person’, :action => ‘updateattribute’, :id => person.id } %> <%end%> |
#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