Hi guys I have a react rails project .I was trying to add some validation and error messages to my project. I made some changes will signing up .However im getting internal server error.500.
the error is "SyntaxError (/Users/max/Development/code/Mod5/capstone/app/controllers/users_controller.rb:36: syntax error, unexpected `end', expecting end-of-input):
app/controllers/users_controller.rb:36: syntax error, unexpected end', expecting end-of-input app/controllers/users_controller.rb:36: syntax error, unexpected
end', expecting end-of-input
" Here is my code
class UsersController < ApplicationController
rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity_response
skip_before_action :authorize, only: [:create]
def create
user = User.create!(user_params)
if user
session[:user_id] = user.id
render json: user, status: :created
else
render json: { errors: ["That Email or Password isnt permitted."]}, status: :unauthorized
end
end
end
def show
render json: @current_user
end
def index
user=User.all
render json: user
end
private
def user_params
params.permit(:name,:email,:password)
end
def render_unprocessable_entity_response(invalid)
render json: { errors: invalid.record.errors.full_messages }, status: :unprocessable_entity
end
end
CodePudding user response:
Your create method only needs 2 end (one for the "def" tag and another for the "end" tag) Here you got 3 tags so one is getting you a syntax error. Try to better indent your code to avoid this kind of mistakes :)