ruby on rails - Pass values from loop inside controller to view -
for simplicity, using easy example.
i have controller method:
def test @books.each |book| @book_id = "emi:#{book.id}" @book_test = ....(some function) end end
how pass '@book_id' & '@book_test' values loop view page?
please note don't want repeat code in view page. want pass values in loop view page.
you have @books in test method why making loop in method? in view file directly no repetation needed.
or other wise make 2 arrays @book_ids , @book_tests , collect prepared values , use them in views following:
def test @book_ids=[] @book_tests=[] @books.each |book| @book_ids << "emi:#{book.id}" @book_tests << ....(some function) end end