ruby-on-rails – 在语言环境文件中使用辅助方法?
我正试图使用??Rails 3获得
Gitorious并运行,但我遇到了一个问题.
我在视图中有这一行. <p><%= t("views.commits.message").call(self,tree_path(@commit.id)) %></p> 相应的语言环境行看起来像这样[config / locales / en.rb] :message => lambda { |this,path| "This is the initial commit in this repository," + this.link_to( "browse the initial tree state",path ) + "." } 这里的问题是lambda方法没有使用#callin在视图中调用,它被其他人调用,这意味着这不是传递给它的self. 这包含views.commits.message和路径包含{:rescue_format =>:html}. 我做了一些研究,找到了关于确切线的this线程. 这是问题的解决方案.
我试图卸载i18n,但运行bundle install只是再次安装它. 如果不重构700行语言环境文件,我该如何解决这个问题呢? 解决方法
这是一个常见问题,如何分解复杂的嵌套文本.
使用markdown来简化它 This is the initial commit in this repository [browse the initial tree state](http://example.com/some/path) . 或许用中文你会说 这是第一个提交在这个知识库 [看初始状态](http://example.com/some/path) . 我们要考虑三件事; >外文 如果链接相对于文本的位置不需要更改,则@WattsInABox更正. views.commits.message: "This is the initial commit in this repository" views.commits.browse: "browse the initial tree state" 然后我们只是撰写 <p> <%= t "views.commits.message" %> <%= link_to t("views.commits.browse"),tree_path(@commit.id) %> . </p> 但有时秩序和位置确实重要, views.commits.message: "This is the initial commit in this repository %{link}" views.commits.browse: "browse the initial tree state" 然后我们可以在正确的位置插入链接 <p> <%= t "views.commits.message",link: link_to(t("views.commits.browse"),tree_path(@commit.id)) %> </p> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |