繁体   English   中英

如何在Ruby中多次传递相同的参数

[英]how to pass same parameter multiple times in ruby

我在Ruby中有以下索引方法

def index
  if params.key?(:item)
    @items = Item.get_items.where(item: params[:item])
  else
    @items = Item.get_items
end

我正在使用邮递员进行测试,如下所示

http://localhost:3000/items?item=some_item

怎样才能两次通过相同的参数?

例如

http://localhost:3000/items?item=some_item&item=other_item

编辑:添加视图

index.json.jbuilder

json.array! @items, partial: ‘items/item’, as: :item

_item.json.jbuilder

json.something1 item.something1
json.item_layout do
  json.template_key item.layout
  json.merge! item.layout_config if item.layout_config.present?
end
json.something (item.item_details) do |item_detail|
  json.partial! ‘item_details/item_detail’, item_detail: item_detail
end

您是说像数组? 试试这个

http://localhost:3000/items?item[]=some_item&item[]=other_item

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM