Ramin Farajpour Cami
Ramin Farajpour Cami

Reputation: 1685

can not display hash in index.html.erb RoR

I unable to access to data DB for show in index.html.erb , when i create controller and my action set this code :

 def index
   @posts = Post.all
 end

and in index.html.erb i use this code:

<% @posts.each do |lst| %>
    <h2> <%= lst.title %> </h2>
    <h2> <%= lst.content %> </h2>

<% end %>

but i have 3 record in DB,when i see view source index.html.erb empty tag 3 records:

    <h2>  </h2>
    <h2>  </h2>

    <h2>  </h2>
    <h2>  </h2>

    <h2>  </h2>
    <h2>  </h2>

Upvotes: 0

Views: 253

Answers (1)

Cremz
Cremz

Reputation: 838

after installing https://github.com/pry/pry you can write something like:

<% @posts.each do |lst| %>
<% binding.pry %>
<h2> <%= lst.title %> </h2>
<h2> <%= lst.content %> </h2>

then when you refresh the page, in the terminal where you are running the server you will see that you get a console and you can see what values you have for lst variable

Upvotes: 1

Related Questions