I have a simple update
action in a Rails 4
controller:
#more stuff here
def update
if @user.update(user_params)
flash[:notice] = "User #{@user.username} updated"
redirect_to users_path
else
render 'edit'
end
end
private
def set_user
@user = User.find(params[:id])
end
However, RubyMine is warning about @user.update
and @user.username
:
This inspection warns if a controller action contains more than one model method call, after the initial .find or .new. It’s recommended that you implement all business logic inside the model class, and use a single method to access it.
I don't see more than one model method call
here. Can some one explain what is going on?
EDIT - I have something similar in the create
action without warns, so I believe there is something to do with user_params
...
def create
if @user.save
flash[:notice] = "User #{@user.username} created"
redirect_to users_path
else
render 'new'
end
end
Assuming username
is a method in model where you merge user first_name
and last_name
.
I guess @user.update(user_params)
and @user.username
are your both method calls. One that saves the model, another that sets the user full name in flash notice.
It's just a warning from rubymine that just recommends you some actions to do, not necessary to follow them.