Ramiz Raja
Ramiz Raja

Reputation: 6030

link_to_function not working properly

I upgraded rails application from rails 2.3.14 to rails 3.2.6. link_to_function is not generating right html.

following helper method . . .

link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))

is generating ...

<a href="#" onclick="add_fields(this, &amp;quot;quick_facts&amp;quot;, &amp;quot;&amp;lt;div class=\'quick_fact\'&amp;gt;\n  &amp;lt;div class=\'grid_4 prefix_1\'&amp;gt;\n    &amp;lt;label for=\&amp;quot;organization_quick_facts_attributes_new_quick_facts_quick_fact\&amp;quot;&amp;gt;QuickFact&amp;lt;\/label&amp;gt;\n    &amp;lt;br&amp;gt;\n    &amp;lt;select class=\&amp;quot;quick_fact_select\&amp;quot; id=\&amp;quot;organization_quick_facts_attributes_new_quick_facts_quick_fact\&amp;quot; name=\&amp;quot;organization[quick_facts_attributes][new_quick_facts][quick_fact]\&amp;quot;&amp;gt;&amp;lt;option value=\&amp;quot;\&amp;quot;&amp;gt;&amp;lt;\/option&amp;gt;\n    &amp;lt;option value=\&amp;quot;Hours\&amp;quot;&amp;gt;Hours&amp;lt;\/option&amp;gt;\n    &amp;lt;option value=\&amp;quot;Serving\&amp;quot;&amp;gt;Serving&amp;lt;\/option&amp;gt;\n    &amp;lt;option value=\&amp;quot;Insurance Accepted\&amp;quot;&amp;gt;Insurance Accepted&amp;lt;\/option&amp;gt;\n    &amp;lt;option value=\&amp;quot;Features\&amp;quot;&amp;gt;Features&amp;lt;\/option&amp;gt;\n    &amp;lt;option value=\&amp;quot;Services Provided\&amp;quot;&amp;gt;Services Provided&amp;lt;\/option&amp;gt;&amp;lt;\/select&amp;gt;\n    &amp;lt;br&amp;gt;\n  &amp;lt;\/div&amp;gt;\n  &amp;lt;div class=\'clear\'&amp;gt;&amp;lt;\/div&amp;gt;\n  &amp;lt;div class=\'grid_4 prefix_1\'&amp;gt;\n    &amp;lt;label for=\&amp;quot;organization_quick_facts_attributes_new_quick_facts_content\&amp;quot;&amp;gt;Content&amp;lt;\/label&amp;gt;\n    &amp;lt;br&amp;gt;\n    &amp;lt;input id=\&amp;quot;organization_quick_facts_attributes_new_quick_facts_content\&amp;quot; maxlength=\&amp;quot;200\&amp;quot; name=\&amp;quot;organization[quick_facts_attributes][new_quick_facts][content]\&amp;quot; size=\&amp;quot;200\&amp;quot; type=\&amp;quot;text\&amp;quot; /&amp;gt;\n    &amp;lt;br&amp;gt;\n  &amp;lt;\/div&amp;gt;\n  &amp;lt;div class=\'clear\'&amp;gt;&amp;lt;\/div&amp;gt;\n  &amp;lt;div class=\'grid_2 prefix_1 exempt\'&amp;gt;\n    &amp;amp;nbsp;\n    &amp;lt;a href=\&amp;quot;#\&amp;quot; class=\&amp;quot;remove_temp_qf\&amp;quot;&amp;gt;remove&amp;lt;\/a&amp;gt;\n  &amp;lt;\/div&amp;gt;\n&amp;lt;\/div&amp;gt;\n&amp;quot;); return false;">Add Another QuickFact</a>

when this html is rendered, onclick function is not being called and here is the error.

syntax error

add_fields(this, &quot;quick_facts&quot;, &quot;&lt;div class=\'quick_fact\'&gt;...

quick_facts# (line 1, col 17)

any idea to solve this??

Upvotes: 0

Views: 247

Answers (1)

averell
averell

Reputation: 3782

The #h method has changed in Rails 3, and Rails 3 is now automatically escaping "unsafe" strings. See this question for more info.

Upvotes: 1

Related Questions