控制器动作被调用两次

Ant*_*nAL 4 action controller ruby-on-rails halting-problem

我注意到,我的控制器的"索引"动作被调用了两次.

该行动具有以下结构:

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
Run Code Online (Sandbox Code Playgroud)

在页面上我有链接与URL,如"/ items?tags = tag1,tag2",点击它们我得到"索引"动作,被叫两次

我不知道,为什么会这样呢......

Ant*_*nAL 5

我已经明白了.

这种行为的原因是JavaScript代码,在页面加载后调用.此代码实现了页面某些部分的深层链接.

小心这个.

谢谢.