Search code examples
ruby-on-railsruby-on-rails-3link-to

How to make :confirm in link_to working with I18n.t() in Rails 3.2?


The following :confirm pops up a window asking 'Delete the record?':

<%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => 'Delete the record?'

If adding I18n.t() to the message, however the confirm window does not pop up:

<%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => I18n.t('Delete the record?')

I tried "#{I18n.t()}" and not working. Is there a way the message can be I18n.t?


Solution

  • The syntax is correct.

    Try this -
     Add some key in your config/locales/*.yml
     confirm_delete: 'Delete Record'
    

    Use this key as-

    <%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => I18n.t('confirm_delete') %>