0

I have code that looks like this that I need to understand:

<ul class="dropdown-menu">
    <li><%= link_to  t('menubar.yes.okay') , admin_ok_path %></li>
</ul>

In this code, what is menubar.yes.okay and where is that defined? Similarly, where is admin_ok_path defined?

The reason I ask is because I would like to add another menu bar item. And if I write something like

<li><%= link_to  t('menubar.yes.no') , admin_ok_no %></li>

then I get an error saying admin_ok_no is not defined. So, what do I need to define in order to set up this new menu bar option? I have already added a No: "No" in my en.yml, but it is still the same error. Note that I have checked my routes.rb and there is no definition of admin_ok_path however that works fine - it shows up in the menubar.

CodeGuy
  • 28,427
  • 76
  • 200
  • 317
  • `menubar.yes.okay' likely to be defined in config/locales/en.yml. See http://guides.rubyonrails.org/i18n.html – osahyoun Apr 14 '13 at 16:16
  • admin_ok_path - see your routes file - config/routes.rb http://guides.rubyonrails.org/routing.html – osahyoun Apr 14 '13 at 16:16

4 Answers4

0

This is defined dynamically. If you run

rake routes

you will get the all available routes,

http://guides.rubyonrails.org/routing.html

admin_ok_path is a path helper defined by rails it self for the matching route admin_ok,

if you run rake routes from application route directory, you will get matching admin_ok route.

admin_ok_path will provides a relative url and admin_ok_url will give you the absolute url.

maximus ツ
  • 7,949
  • 3
  • 25
  • 54
  • See updated question. What do I need to define in order to get a new menu bar item working. I already added the update in en.yml and it still has same error – CodeGuy Apr 14 '13 at 16:22
  • firstly you need translation to local file as said by Intrepidd, then add route to the routes for admin_ok_no like get "url_path" => "controller#action", :as => admin_ok_no – maximus ツ Apr 14 '13 at 16:25
0

The helper t, short for I18n.t is used for internationalization

For example, in config/en.yml, if you have :

menubar:
  yes:
    okay: Okay

This will write "Okay"

admin_ok_path is a dynamically generated helper for the routes path. You can see all of them by running rake routes

Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • See updated question. What do I need to define in order to get a new menu bar item working. I already added the update in en.yml and it still has same error – CodeGuy Apr 14 '13 at 16:22
0

t is short for translate. You'll find the localization files in config/locales - they're basically YAML files that define strings. See more here

The admin_path_ok method is a route helper that returns a path. See your config/routes.rb file. More info here

Flambino
  • 18,507
  • 2
  • 39
  • 58
  • See updated question. What do I need to define in order to get a new menu bar item working. I already added the update in en.yml and it still has same error – CodeGuy Apr 14 '13 at 16:20
  • admin_path_ok is not defined in my routes.rb – CodeGuy Apr 14 '13 at 16:28
  • @CodeGuy if it's being generated by your routes file (i.e. it's not listed when you run `rake routes`), it's probably in a helper file. Check `app/helpers` and see if one of the files there (likely `application_helper.rb`) defines a `admin_path_ok` method. If not, it can be a method defined in a controller (in `app/controllers`), and "exported" using `helper_method :admin_path_ok` – Flambino Apr 14 '13 at 23:04
0

'menubar.yes.okay' likely to be defined in 'config/locales/en.yml'. And rake routes | grep admin will give you all the routes related to admin.

ted
  • 5,219
  • 7
  • 36
  • 63
Ranjan Kumar
  • 49
  • 1
  • 8