My rails users_controller
is receiving ajax data at its update_tool
path.
My intent is to decrement the users dollars
by the price of the tool, and add that tool's id to the users's tool_id
(which references a tool table).
I'm receiving :user_id
and :toolId
in params.
Heres my controller:
def update_tool
redirect_to :index
@user = User.find(params[:user_id])
@tool = Tool.find(params[:toolId])
price = @tool.price
# subtract tool price from users dollars
@user.dollars = @user.dollars - price
# re-assign users tool_id reference ID
@user.tool_id = @tool.id
#store to database
@user.save
end
However, when I trigger this path, nothing seems to happen, and I recieve the following error in my browsers console:
BROWSER ERROR:
PATCH http://localhost:3000/update_dollars 500 (Internal Server Error) jquery.js?body=1:5
My server logs show:
LOGS:
ActionView::MissingTemplate (Missing template users/update_dollars, application/update_dollars....(etc)
Is my controller trying to find a view to render? If so why?
How can I simply have the controller update the database, without taking any further action?
You can do this:
render nothing: true
in your update_tool
action.
Please check this for reference: