pictonica
pictonica

Reputation: 23

Ruby syntax error - unexpected end-of-input, expecting keyword_end

I have this error in Rails 4.1.4, but I can't see where should be the problem: syntax error, unexpected end-of-input, expecting keyword_end

class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

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

  def new
    @post = Post.new
  end

  def create
    @post= Post.new(post_params)
    if @post.save
      redirect_to posts_path
    else
      render "new"
    end
  end

  def edit
  end

  def update
  end

  def destroy
  end

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

Upvotes: 2

Views: 3519

Answers (2)

Adim Victor
Adim Victor

Reputation: 104

The Problem i see with is with where you declared the private method, you did not indent the post_params method properly and the private method has no "end"

Do this instead..

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

Upvotes: 0

anusha
anusha

Reputation: 2135

Try adding this in new method

Post.new(params[:post].permit(:title, :content)

and remove that private method

Upvotes: 1

Related Questions