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 

Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -