关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。
想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。
上个月关闭。
Improve this question
我注意到,我的 Controller 的“索引”操作被调用了两次。
该 Action 具有以下结构:
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
在页面上,我有 URL 链接,比如“/items?tags=tag1, tag2”,点击它们我得到“index” Action ,调用两次
我不知道,为什么会发生这种情况......
最佳答案
我已经想通了。
这种行为的原因是 JavaScript 代码,在页面加载后被调用。此代码为页面的某些部分实现了深层链接。
小心这一点。
谢谢。
关于ruby-on-rails - Controller Action 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3930332/