Reputation: 752
I'd like to create a simple blog without the scaffold generator. I generated the controller and manually created the views.
First I define the create
action( including def new) in the controller and then I proceeded to make the views. After that, I create a model called article
and added fields like title and body. The show views are alright but when I created the index page and looped through all the articles, the model data are also shown.
First article <3 Second Article
[#Article id: 1, title: "First article <3", body: "This is the body of the first article and i create...", by: "Ahmad Aziz", created_at: "2015-03-30 11:50:03", updated_at: "2015-03-30 11:56:37">, #Article id: 2, title: "Second Article", body: "This is the second article", by: "Ahmad Aziz", created_at: "2015-03-30 11:53:31", updated_at: "2015-03-30 11:57:13">]
How can i remove the model data from the index page? thank you.. I am sorry if my explanation is bad. I don't really know what this thing is called.
I'm using rails 4.2
.
Upvotes: 0
Views: 57
Reputation: 630
Make sure you aren't doing something like
<%= @articles.... %>
Somewhere.
That "=" right there would print the object.
Upvotes: 0
Reputation: 2384
You would need to loop through your model and call the fields that you want on to display on the page...ie:
index.html
<% @articles.each do |article| %>
<h1> <%= article.title %> </h1>
<p> <%= article.body %> </p>
<% end %>
If you just print the article itself, you're going to get the who object
Upvotes: 0