0

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.

bobbdelsol
  • 996
  • 6
  • 21

1 Answers1

1

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

house9
  • 20,359
  • 8
  • 55
  • 61
  • All thee methods take care of the space issue. I went with the quotes around the erb, since i was using the – bobbdelsol May 10 '14 at 21:28