I am trying to get my Posts controller to work and I keep getting these error messages:
undefined method 'each' for `#<Post:0x000000062820c0>`
and : match ? attribute_missing(match, *args, &block) : super
I just included Attribute Methods but the error is still the same. I am posting my controller file below. Thanks for the help.
class PostsController < ApplicationController
include ActiveModel::AttributeMethods #Just added this..the error message was the
#same without it.
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post #.find(params[:id])
else
render :new
end
end
def show
@post = Post.find(params[:id]) # show
end
private
def post_params
params.require(:Title).permit(:Body, :url)
end
end
Here is the show view:
<h1>Posts</h1>
<% @post.each do |post| %>
Title: <%= post.Title %><br>
Body: <%= post.Body %><br>
url: <%= post.url %><br>
<% end %>