user3285714
user3285714

Reputation: 75

Rails asking for "end", but everything has an end?

Ok, so I am trying to learn Rails by watching YouTube; so far I am having a better understanding as I go along.

Problem is, I am using Rails 4 whereas the vidoe uses Rails 3. No big deal. There was a problem with the video's code, so someone posted in the comments section some corrected code.

Problem is, I get this error:

SyntaxError in PostsController#create
/home/chris/blog/app/controllers/posts_controller.rb:43: syntax error, unexpected end-of-input, expecting keyword_end

Now I've gone through my code, looked it all over, and from what I do know of Rails so far, everything has an appropriate end. I have used comments and, for every beginning, there is an 'end'. But I have definitely messed something up. And yes this is Rails 4.0 I am using.

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

  def create#2
    @post=Post.new(post_params)

    if @post.save#2.1
      redirect_to posts_path, :notice =>"Your post was successfully saved"
    else
      render "new"
    end#2.1
  end#2

  def new#3
    @post=Post.new
  end#3

  def edit#4
  end#4

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

  def update#6
  end#6

  def destroy#7
  end#7

  private
  def post_params#1
    @allow = [:title, :content]
    params.require(:post).permit(@allow)
  end#1
end#main

Upvotes: 2

Views: 55

Answers (1)

htanata
htanata

Reputation: 36954

There seems to be a stealth byte order mark character between end# and #1 near the end. Here's how it looks on my editor:

enter image description here

Deleting that line and typing it again fixed it for me.

Upvotes: 4

Related Questions