I'm getting a syntax error with what you see below.
What's weird is if I run: ruby -c controllers/posts_controller.rb
I get back Syntax OK
... I'm not sure exactly what's causing this to occur.. All of my definitions and classes are closed with "end" and from what I can tell it's all cased the same. What gives?
Syntax Error: /home/action/workspace/zjmw00.5/app/controllers/posts_controller.rb:27: syntax error, unexpected keyword_end, expecting end-of-input
posts_controller.rb
class PostsController < ApplicationController
def new
end
# Create a private definition to secure the post parameters and then link it to create.
# Make sure all private definitions are at the bottom so that your others aren't private.
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def show
@post = Post.find(params[:id])
end
def index
@post = Post.find(1, 2, 3)
end
private
def post_params
params.require(:post).permit(:title, :text)
end
end
views/posts/index.html.erb
<h1>Listing posts</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.text %></td>
</tr>
<% end %>
</table>
EDIT:
New error: /home/action/workspace/zjmw00.5/app/models/post.rb:5: syntax error, unexpected keyword_end
index.html.erb
<h1>Listing posts</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @post.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.text %></td>
</tr>
<% end %>
</table>
posts_controller.erb
class PostsController < ApplicationController
def new
end
# Create a private definition to secure the post parameters and then link it to create.
# Make sure all private definitions are at the bottom so that your others aren't private.
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def show
@post = Post.find(params[:id])
end
def index
@post = Post.all
end
private
def post_params
params.require(:post).permit(:title, :text)
end
end
As requested (post.rb)
class Post < ActiveRecord::Base
belongs_to :user
validates :title, :text,
presence: true,
end
Post.find(1, 2, 3)
. – PericlesTheo Dec 16 '14 at 18:18presence: true
– xlembouras Dec 16 '14 at 18:26