这个ruby类引发了一个错误用户是表的名称,所以我不知道为什么它说索引方法中的错误是因为Users.all必须返回零 C:/ProyectosRails/gag_cf/app/models/user.rb:4:语法错误,意外' \ n',期待tASSOC
提取的来源(第7行):
# GET /users.json
def index
@users = User.all
end
这是控制器
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
end
def new
@user = User.new
end
def edit
end
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render action: 'show', status: :created, location: @user }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end
class User < ActiveRecord::Base
authenticates_with_sorcery!
validates_confirmation_of :password, message: "Both fields must match", if :password
end
答案 0 :(得分:1)
你有一个额外的逗号(,
)。删除此额外,
。以下代码取自OP的comment。
class User < ActiveRecord::Base
authenticates_with_sorcery!
validates_confirmation_of :password, message: "Both fields must match", if :password
# see|
end