Home how to pass same parameter multiple times in ruby
Reply: 1

how to pass same parameter multiple times in ruby

mike
1#
mike Published in 2017-11-13 22:47:03Z

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?

e.g

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
Ursus
2#
Ursus Reply to 2017-11-13 22:49:06Z

You mean, like an array? Try this way

http://localhost:3000/items?item[]=some_item&item[]=other_item
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314724 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO