jeudi 28 avril 2016

Rails table data shows as a hash under the real table data in Browser

I am trying to display all of the blog posts on the index page, but whenever I go to it, it displays what I want, and then below it, it puts the rest of the data as a hash. I want the first post and first description to be in the browser but I don't want the hash under it to be in there. Screenshot of how the data from the table shows up

This is my posts_controller.rb

class PostsController < ApplicationController

  def index
    @post = Post.all
  end

  def show
    @post = Post.find(params[:id])
  end

  def new
    @post = Post.new(params[:id])
  end

  def create
    @post = Post.new(post_params)

    @post.save
    redirect_to @post
  end
end

private
def post_params
  params.require(:post).permit(:title, :description)
end

This is my index.html.erb file

<h1>Blog Posts</h1>

    <table>
      <th>Title</th>
      <th>Description</th>
      <div><%= @post.each do |post| %></div>
      <tr>
        <td><%= post.title %></td>
        <td><%= post.description %></td>
      </tr>
    </table>
    <% end %>

Any help would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire