I'm trying to create a service that will check if a user exists
class UserService
def create_user(user_username, user_email)
if User.find(user_username)
false
end
if User.find(user_email)
false
end
true
end
end
And I call it on the chalkboard of my controler
def create
if UserService.create_user(params[:username], params[:email])
@user = User.new(user_params)
if @user.save
render json: @user, status: :created, location: api_user_path(@user)
end
render json: "exist", status: :unprocessable_entity
end
render json: @user.errors, status: :unprocessable_entity
end
But this is giving error on the line where I call
undefined method 'create_user' for UserService:Class
claim can you help me? I'm new with ruby on rails and actually I even asked another question about how services work, but there I found some things and tried to start on my own, but I have no idea if what I'm doing is right.
Just to make it clear I know it would work if I put it right in the controler, but I'm trying to learn how to use services in ruby, so I'm doing it that way.