I can not the results of database on browser when pushing it to open shift,while it works okay on my localhost machine, some one knows what is going there?
controler
class PostController < ApplicationController
def index
@post = Post.all
end
def show
end
def new
end
def edit
end
def delete
end
end
model
class Post < ActiveRecord::Base
attr_accessible :email, :text, :title
end
index.html.erb
<h1>index</h1>
<% @post.each do |p| %>
<br />
<%= p.email %>
<%= p.title %>
<% end %>
out put:
index
[]
ERB
has different kind of tags. The main ones are:<% ruby code %>
, which executes an operation in context,<%= ruby code %>
, which executes an operation in context and outputs its result,<%# anything %>
, which inserts a comment.You typically use
2
to write things on the page, either on their own or inside a block or loop defined with1
-- see what I meant when I said in context?Your code should be:
aside from that, the output you are getting,
[]
, is the result of the first operation:<%= @post.each do |p| %>
. It might mean that you've got an empty list.this
is wrong
Remove the "="
You don't need to use equal sign for the loop in your html page
replace this line
to
and make sure you will have some records in your post controller otherwise you will get empty array like this: