Controller action is called twice [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
开发者_JAVA技巧 Improve this questionI've noticed, that "index" action of my controller is called twice.
The action has following structure:
def index
if params[:tags].nil?
# [fork #1] just return the whole collection of model
@items = Item.all
else
# [fork #2] filter items by tags
@items = Item.select_by_tags params[:tags]
end
# Another operations with @items
# The result will be incorrect, because, when tags in params are specified,
# controller action will be first executed for fork #2, and then for fork #1.
# In view, i get @items from fork #2 and result of THIS piece of code for fork #1
end
On the page i have links with URLs, like "/items?tags=tag1, tag2", clicking on them i get "index" action, called twice
I have no idea, why this happens ...
I've figured it out.
The reason of such a behavior was a JavaScript code, being called after page load. This code implements deep-linking for some parts of the page.
Be careful about this.
Thanks.
I faced similar issue and in our case it was an offending pjax code with 6s of timeout resulting in one extra request (i.e. one extra regular HTML request) if pjax didn't complete in 6s.
Another thing to check is whether you have PostCSS listed as a dependency in your package.json
. If you do, and you don't have a postcss.config.json
file, fix that. The most basic file appears to be
module.exports = {
plugins: []
}
Restart your server, reload your page, and check the server log. There should be only one request being reported as processed.
Very late to the party, but hope this helps someone. I was temporarily stumped in a trivial Rails 6.1.4.1 app seeing the log.
精彩评论