小编Car*_*ate的帖子

Ruby on Rails - redirect_to 'index' 和 redirect_to objects_path & redirect_to action 之间的区别:'index'

我有一个简单的模型和控制器。我们以猕猴桃为例:

def index
    @kiwis = Kiwi.all
end

def destroy
    kiwi = Kiwi.find(params[:id])
    kiwi.destroy
    redirect_to 'index'
end
Run Code Online (Sandbox Code Playgroud)

我在索引页面上使用了删除链接。当我使用 redirect_to 'index' 页面不会刷新模型。我必须在页面上进行硬刷新才能删除 Kiwi。但是,如果我使用 redirect_to action: 'index' 或 redirect_to kiwis_path 页面将在销毁操作后更新。我似乎无法找到对此的解释。任何人都可以对这个问题有所了解。

ruby model-view-controller controller ruby-on-rails ruby-on-rails-4

5
推荐指数
1
解决办法
3182
查看次数