且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换字符串中的模式

更新时间:2022-12-10 23:41:58

我会针对链接执行此操作

I would do this for the links

<%= ([1,2,3]- [params[:x]]).each do |link_number| %>
   <%= link_to "Version #{link_number}", "/page?x=#{link_number}" %>
<% end %>

这样,每次加载页面时,都会存在指向其他2个版本的链接。

This way everytime the page is loaded the link to the other 2 versions will exist.

您可以通过控制器处理部分零件(似乎更好),也可以使用类似的东西:

You could handle the partials through the controller (which seems better) or use something like:

<%= render "version_#{['A','B','C'][params[:x] - 1]}" %>

在没有更好地理解问题的情况下,我无能为力。

Without a better understanding of the problem I cannot assist beyond this point.