开发者

Controller action is called twice [closed]

开发者 https://www.devze.com 2023-01-19 19:01 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

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 question

I'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消