2

I have the following code in my Ruby Controller :

mastertest_controller.rb

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}

 end

But it just allows me to access @mastertest in the view(index.html.erb). How do I pass the array to the view ???

1 Answer 1

8

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

Controller:

@result_array = [something, second_something]

Then in your view:

<% @result_array.each do |item| %>
  <%= item %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.