大家好,我有一個 react rails 專案。我試圖向我的專案添加一些驗證和錯誤訊息。我做了一些更改將注冊。但是我收到內部服務器錯誤。500。
錯誤是“SyntaxError(/Users/max/Development/code/Mod5/capstone/app/controllers/users_controller.rb:36:語法錯誤,意外'end',期待輸入結束):
app/controllers/users_controller.rb:36:語法錯誤,意外end', expecting end-of-input app/controllers/users_controller.rb:36: syntax error, unexpected 結束',期待輸入結束
“這是我的代碼
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
uj5u.com熱心網友回復:
您的 create 方法只需要 2 個 end(一個用于“def”標簽,另一個用于“end”標簽)這里有 3 個標簽,所以一個會導致語法錯誤。嘗試更好地縮進你的代碼以避免這種錯誤:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/507443.html
標籤:轨道上的红宝石
