Question

I'm saving some translation data in the data attribute of a DOM element.

<input type='button' id=admin-button data-add= <%=t :Add_Category%> data-save= <%=t :Save%> value= <%=t :Add_Category%> 

unfortunately when the translation file value has a space such as Add_Category:"Add Category"

I get

data-add="Add" category=""

instead of

data-add="add category"

it works if i do it without the translation in between.

Was it helpful?

Solution

Put double quote the around the erb tags? or better use the rails helpers, maybe button_tag

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-button_tag

<%= button_tag t(:add_category), 
  id: "admin-button",
  data: {
    add: t(:add_category),
    save: t(:save)
  }  
%>

this renders a <button> if you must have input type="button", maybe this would work

<%= content_tag :input, 
  t(:add_category), 
  type: "button",
  id: "admin-button",
  data: {
    add: t(:add_category),
    save: t(:save)
  }  
%>

http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag

Also I recommend using all lower case with underscores - i.e. :add_category vs :Add_Category - it is more in the ruby style

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top