ruby on rails - Add link to methods to array in controller -


i have index method in rails 4 application controller looks like:

def index    @products = product.all    @headers = @products.map(&:data).flat_map(&:keys).uniq    @product_data = @products.map{ |product| product[ :data ].values } end 

so @product_data ends like:

[["table", "$199.99", "blue"], ["book", "$9.99", "green"]] 

in view, put of in unordered list. i'd have link_to edit , delete page each product. how can include in array, can display link each product on view page?

you add product_id result of product[:data].values array. use product_id parameter product url_helpers.

@product_data = products.map{ |product| product[ :data ].values.unshift(product.id) } 

this should give similar to:

[[1, "table", "$199.99", "blue"], [2, "book", "$9.99", "green"]] 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -