我完全是Ruby和Nanoc的新手,但是有一个项目已经放在我的腿上了。基本上,页面的代码为每个项目返回单独的URL,将它们链接到手册。我正在尝试创建一个URL,它将在一次搜索中列出所有手册。任何帮助都是非常感谢的。
代码如下:
<div>
<%
manuals = @items.find_all('/manuals/autos/*')
.select {|item| item[:tag] == 'suv' }
.sort_by {|item| item[:search] }
manuals.each_slice((manuals.size / 4.0).ceil).each do |manuals_column|
%>
<div>
<% manual_column.each do |manual| %>
<div>
<a href="<%= app_url "/SearchManual/\"#{manual[:search]}\"" %>">
<%= manual[:search] %>
</a>
</div>
<% end %>
</div>
<% end %>
</div>发布于 2018-05-09 03:47:00
因为您没有指定返回哪些项,所以我做了一个通用的示例:
require 'uri'
# let suppose that your items query has the follow output
manuals = ["Chevy", "GMC", "BMW"]
# build the url base
url = "www.mycars.com/search/?list_of_cars="
# build the parameter that will be passed by the url
manuals.each do |car|
url += car + ","
end
# remove the last added comma
url.slice!(-1)
your_new_url = URI::encode(url)
# www.mycars.com/?list_of_cars=Chevy,GMC,BMW
# In your controller, you will be able to get the parameter with
# URI::decode(params[:list_of_cars]) and it will be a string:
# "Chevy,GMC,BMW".split(',') method to get each value.一些注意事项:
<% %>语法来包装代码。关于URL格式,你可以找到更多关于如何构建它的选择:Passing array through URLshttps://stackoverflow.com/questions/50237862
复制相似问题