I don’t want to use the default
<%= f.submit %>
and have created a helper function for it, which also embeds an icon. The helper function expects a label to put on the newly created button.
I’m calling it like this:
<%= submit_button("icon-plus", I18n.translate("helpers.submit.create")) %>
But now on this text appears on the button:
%{model} toevoegen
Instead of:
Product type toevoegen
If I use the normal submit button then the correct text appears so my yml files are correct. How can I get the correct text to use in the helper?
Helper code:
def submit_button(icon, label)
link_to "javascript:void(0)", :class => 'btn btn-primary', :onclick => "$(this).closest('form').submit()" do
raw('<div class="') + icon + raw(' icon-white"> ') + label +raw('</div>')
end
end
As the I18n guide says, the
translatefunction interpolates variables passed in the%{}brackets using its second argument (a hash).In your case you need to tell it the
modelby doing this:If you want a generic option that would work for any model, you can see how Rails itself does it by looking at the source on GitHub – it’s something like
As an aside, you don’t need to (and probably shouldn’t) use
rawthere. What you are trying to achieve could easily be done with the built-in helpers: