I have a project that add users, profiles, etc.
I genetered it using scaffold. It's everything ok up here.
I need to do the crud operations in a service class and not in the
controllers.
I created a services folder into App folder and create a UserService.rb
class .
So the idea is that the controller call to UserService class , and the
userService Class do the crud(create, read, update, delete) operation.
But I got this error message : uninitialized constant
UsersController::UserService .
I tried add a instance to routes.rb , also to application.rb but the
error is still there.
I have searched many examples and tried many things, but can not find
solution.
#App/Controller/user_controller
def create
@user = UserService.create(params[:user_params])
end
#App/services/UserService.rb
^^ If this is the *actual* name of the file, then Rails autoloading will
not work on it. When Rails encounters a class called "UserService" it looks
through the autoload paths for a file entitled: "user_service.rb" (i.e.
snake case, not CamelCase).
Look at the name of the class (UserService). Now look at the name of
the file. Now look again if necessary. Keep looking...
Colin
I tried changed the name of el file from UserService to user_service.
the class name is UserService.
Correct the code in your repo then copy/paste here the error you get
with the correct name.
The code is still wrong in the repo. As I said, correct the code in
the repo, make sure that is the code you are running, and try again.
It is difficult to help if you do not do what is asked.
Correct the code in your repo then copy/paste here the error you get
with the correct name.
The code is still wrong in the repo. As I said, correct the code in
the repo, make sure that is the code you are running, and try again.
It is difficult to help if you do not do what is asked.
Colin
I corrected the code in the repo. The file name is user_service.rb and
the class name is : UserService.