I am new to programming and teaching myself RoR. I am using http://ruby.railstutorial.org as my first guide. I thought I was doing well, then a seemingly simple issue came up that even after several reads of good post on stack related to this topic I still can't fix it. I would appreciate it if someone could kindly point out the issue/s I have within my code.
Thank you.
I am getting this error.
C:/Sites/rails_projects/sample_app/app/controllers/users_controller.rb:23: syntax error, unexpected $end, expecting kEND
Here is the code I am using:
class开发者_StackOverflow社区 UsersController < ApplicationController
def show
@user = User.find(params[:id])
@title = @user.name
end
def new
@user = User.new
@title = "Sign up"
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
@title = "Sign up"
render 'new'
end
end
Check the indentation in your create
method. You didn't indent anything under the if @user.save
. I know that seems a bit off-topic, but if you had the indentation right, you'd see that the there is no end
closing the class.
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@title = @user.name
end
def new
@user = User.new
@title = "Sign up"
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
@title = "Sign up"
render 'new'
end # <= ends the if
end # <= ends the def create
end # <= ends the class
精彩评论