0

This is my code and it is loaded in a helper-class

output += '<button class="del_account" param-del="{account.id}">delete</button>'

When I render this to html, account.id is just converted to a string. And not the 'id' that I need. How can I solve this? Because this isn't working either.

output += '<button class="del_account" param-del="#{account.id}">delete</button>'

or this

output += '<button class="del_account" param-del="' +account.id +'">delete</button>'

thanks for your help.

2 Answers 2

3

If you need to use both " and ' symbols then here is simple way to deal with them:

output += %[<button class="del_account" param-del="#{account.id}">delete</button>]

This way you can safely place any of mentioned symbols without worrying to escape them.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use the Rails helper method content_tag (documentation) which makes things a bit cleaner and more readable.

output += content_tag(:button, "delete", :class => "del_account", :'param-del' => account.id)

Also, technically 'param-del' makes your HTML invalid - your custom attributes should begin with 'data-', so updating above would become:

output += content_tag(:button, "delete", :class => "del_account", :'data-account-id' => account.id)

1 Comment

Yes, I like this more than above. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.