2

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
15
  • 10
    looks ok... can you please post the stack trace. Commented Jul 4, 2014 at 9:30
  • for which action you got that error? Commented Jul 4, 2014 at 9:31
  • 1
    it may be the problem in your view , you can check view file also Commented Jul 4, 2014 at 9:36
  • in browser i have marked last end Commented Jul 4, 2014 at 9:36
  • 1
    I do not see any error: i can just add this file to my project and it parses correctly. Commented Jul 4, 2014 at 9:43

2 Answers 2

1

Try adding this in new method

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

and remove that private method

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.