This was a simple fix. You dont escape html in rails 3.
On Mar 26, 5:38 pm, John Merlino <stoici...-YDxpq3io04c@public.gmane.org>
wrote:> I have a form helper that looks like this:
>
> #_alert.html.haml
> = add_field_link "Add Email", f, :notification_emails
>
> #application_helper.rb
> def add_field_link(name, f, association)
> new_object >
f.object.class.reflect_on_association(association).klass.new
> fields = f.fields_for(association, new_object, :child_index =>
> "new_#{association}") do |builder|
> render("home/" + association.to_s.singularize +
"_fields", :f =>
> builder)
> end
> link_to_function(name,
>
h("add_fields(this,''#{association}'',''#{escape_javascript(fields)}'')"))
> end
>
> :javascript
> function add_fields(link, association, content) {
> var new_id = new Date().getTime();
> var regexp = new RegExp(''new_'' + association,
''g'');
>
$(link).prev(''ul'').append(''<li>'' +
content.replace(regexp, new_id)
> + ''</li>'');
> }
>
> This line here I had to use '' rather than "/ because
otherwise
> firebug will raise error "unexpected token &":
>
> link_to_function(name,
>
h("add_fields(this,''#{association}'',''#{escape_javascript(fields)}'')"))
>
> but when I click on link its supposed to add a new field with model
> attributes but doesnt. I look in firebug console and see this:
>
> <a href="#"
onclick="add_fields(this,''notification_emails'',''&lt;li
> class=\''fields\'' style=\''list-style-type:
none;\''&gt;\n
> &lt;input id>
\&quot;alert_rule_notification_emails_attributes_new_notification_email
s_email
> \&quot;
name=\&quot;alert_rule[notification_emails_attributes]
> [new_notification_emails][email]\&quot; size=\&quot;
> 30\&quot; type=\&quot;text\&quot; /&gt;\n
> &lt;input id>
\&quot;alert_rule_notification_emails_attributes_new_notification_email
s__destroy
> \&quot;
name=\&quot;alert_rule[notification_emails_attributes]
> [new_notification_emails][_destroy]\&quot;
type=\&quot;hidden
> \&quot; value=\&quot;false\&quot; /&gt;\n
> &lt;input id>
\&quot;alert_rule_notification_emails_attributes_new_notification_email
s__destroy
> \&quot;
name=\&quot;alert_rule[notification_emails_attributes]
> [new_notification_emails][_destroy]\&quot;
type=\&quot;hidden
> \&quot; value=\&quot;false\&quot;
/&gt;&lt;a href> \&quot;#\&quot;
onclick=\&quot;remove_fields(this); return
>
false;\&quot;&gt;remove&lt;\/a&gt;\n&lt;\/
> li&gt;\n''); return false;">Add Email</a>
>
> Any idea why it looks like this and why the expected behavior doesnt
> occur?
>
> thanks for response
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.