views:

367

answers:

1

Hi All,

Is there a quality way to update the text inside a "link_to_remote" and leave the link functional? Basically I have two links:

  <%= link_to_remote "(#{building.charts.size} Charts)",{:url => {:action => "update_chart_matrix", :chartable_type => "building",:chartable_id => building.id, :title => building.name},
 :update => 'chart-matrix',
}
%>

...and...

<%= link_to_remote "Add Chart",{:url => {:action => "add_chart_for_chartable", :chartable_type => "building",:chartable_id => building.id},
 :update => 'other_link', #really not sure about this part as I only want to update the Chart Count in the other link
}
%>

It would be easy enough to simply replace the HTML inside the link, but I don't want to "break" its functionality. Any ideas?

Thanks.

+1  A: 

Hi humble,

Updating the internal HTML of a link won't break the onclick functionality. You're using update in prototype (via Rails), which set's the innerHTML:

update: function(element, content) {
  element = $(element);
  if (content && content.toElement) content = content.toElement();
  if (Object.isElement(content)) return element.update().insert(content);
  content = Object.toHTML(content);
  // This sets innerHTML, it doesn't destroy the object
  element.innerHTML = content.stripScripts();
  content.evalScripts.bind(content).defer();
  return element;
},

As long as the content coming back is suitable to live inside an a tag, you should be fine.

Good luck!

mixonic