Change in the number-requests
-
Hello, everyone! I'm doing my job to get the request for /urls/:short_url should return the url pages and increase the number of requests by 1 (as I understand, it's the number of them to get.) To this end, I have an Url model that contains fields s_url:string and request_number:integer and a code for the method to show in the counteraller:
def show if !Url.where(s_url: request.original_url.to_s).blank? url = Url.find_by_s_url(request.original_url.to_s) url.request_number += 1 else url = Url.create(s_url: request.original_url, request_number: 1) url.save end
render json: url, status: 200
end
And that's the problem: the counter is raised only once (from 1 to 2), and then not updated at all. This is the line of the database that was altered in the first place. How do you fix that?
-
After the addition, the unit did not write to maintain the database: url.save
Once this line is added, it works.