在Ruby on Rails中的新行上显示确认框文本

时间:2013-06-17 23:30:33

标签: ruby-on-rails internationalization

我的代码在这里工作正常。我关心的一行是:confirm =>

<%= link_to I18n.t('helpers.links.remove_from_your_page'), '#', 
            :confirm => I18n.t('helpers.links.confirmation'), 
            :remote_url => reject_review_path(review),
            :class => 'btn btn-danger remove_page_button_pos remove-from-your-page', 
            :id => "remove_from_your_page_#{review.id}" %>

我的国际化文件有:

Helpers:
 links:
  confirmation: "Are you sure?"

因此,当用户点击该按钮时,在继续操作之前,他们会收到“你确定吗?”的确认框,并带有取消和确定按钮 - 按计划工作。

问题是我想在确认框的行之间放置空格。例如,我想:

Are you sure?

If you do this, that might happen.

If you do that, this might happen.

Cancel     OK

我认为我下面的内容会奏效,但事实并非如此:

(注意'原始',在:确认等......)

<%= link_to I18n.t('helpers.links.remove_from_your_page'), '#', 
            :confirm => raw I18n.t('helpers.links.confirmation'), 
            :remote_url => reject_review_path(review),
            :class => 'btn btn-danger remove_page_button_pos remove-from-your-page', 
            :id => "remove_from_your_page_#{review.id}" %>

在我的国际化中,我有:

Helpers:
 links:
  confirmation: "Are you sure?<br/>If you do this, that might happen. <br/>If you do that, this might happen."

但是我收到语法错误。知道如何让它工作吗?谢谢。

1 个答案:

答案 0 :(得分:1)

您将无法生成HTML标记,但您当然可以insert newlines

Helpers:
  links:
    confirmation: |
      Are you sure?
      If you do this, that might happen.
      If you do that, this might happen."

I18n.t('confirmation') #=> "Are you sure?\nIf you do this, that might happen.\nIf you do that, this might happen.\n"

请记住空白和标签。 YAML非常关注间距的一致性。标准是两个空格的缩进,没有标签。