1
I’m trying to create a service that will check if a Sario 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 him on my controller’s desk
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 giving error in the line where I call
undefined method `create_user' for UserService:Class
Can you help me? I’m new with ruby on Rails and I’ve actually already asked another question about how services work, but then 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 be clear, I know it would work if I put it right into the controller, but I’m trying to learn how to use services in ruby, so I’m doing it this way.
So I’m trying to put in service, to learn how to use the service, no controler to on that works.
– Marcius Leandro