Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is link_to t() in Rails 3?

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

like image 649
jhamm Avatar asked Aug 04 '12 11:08

jhamm


People also ask

How do I create a link in rails?

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.

How do you use link_to in rails?

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.

What is _path in rails?

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?

Is it possible to hardcode a path in rails?

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.


1 Answers

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)

like image 120
Baldrick Avatar answered Sep 30 '22 03:09

Baldrick