Pi Horse Pi Horse - 1 year ago 46
Ruby Question

passing an array from controller to view in ruby

I have the following code in my Ruby Controller :


def index


@mastertest = connection.execute("select code_ver from mastertest")
result_array = { sometihng }


respond_to do |format|
format.html # index.html.erb
format.json { render :json => @mastertest}
format.json { render :json => result_array}


But it just allows me to access
in the view(
). How do I pass the array to the view ???

Answer Source

instance variables in your controller are passed as instance variables in your view.


@result_array = [something, second_something]

Then in your view:

<% @result_array.each do |item| %>
  <%= item %>
<% end %>