简体   繁体   中英

how to pass same parameter multiple times in ruby

I have following index method in ruby

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

I am using postman for testing as follows

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

How can pass same param twice?

eg

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

Edit: adding views

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

You mean, like an array? Try this way

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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