I watched Railscast 328 this morning and I am having difficulty finding docs for a method.
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_boy_scout_path(boy_scout), :class => 'btn btn-mini' %>
I understand the link_to method, but I am confused about the t('edit .... ) parameter and it is in this method call twice. An explanation or even pointing me to some docs would be great. Thanks for all the help
This is the manual way of creating a link. Rails provides a much better way of implementing this functionality, and this is through a tool called link_to. I'm going to use some embedded ruby, so we'll the use the angle bracket, the percent sign, and the equal sign, followed by the link_to method. Next we pass in the description as a string.
The first argument for link_to is the text on the link. The second argument? It’s the URL you’re linking to. You can hardcode it if you want, but most of the time you’ll be using a Rails model, or a _path method. Rails will figure things out when you follow the proper conventions.
It’s the URL you’re linking to. You can hardcode it if you want, but most of the time you’ll be using a Rails model, or a _path method. Rails will figure things out when you follow the proper conventions. How do you know which one to use?
You can hardcode it if you want, but most of the time you’ll be using a Rails model, or a _path method. Rails will figure things out when you follow the proper conventions.
The t
function is an alias for I18n.translate
.
The default:
option gives the translation to use if the requested key is missing (the '.edit'
of your example).
See guide in internationalization (and go to 4.1.2 for the syntax of the :default
option)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With