持续搜索查询
当用户销毁该项目时,我使用此代码来保留我的搜查过滤器。
# In application controller
def get_query(cookie_key)
cookies.delete(cookie_key) if params[:clear]
cookies[cookie_key] = params[:q].to_json if params[:q]
@query = params[:q].presence || JSON.load(cookies[cookie_key])
end
# In my example controller
before_action only: [:index] do
get_query('example_capabilities')
end
def destroy
authorize @example
@example.destroy
respond_to do |format|
format.html { redirect_back fallback_location: get_query('example_capabilities'), notice: 'example was successfully destroyed.' }
format.json { head :no_content }
end
end
当用户编辑项目时我也想使用它,但我没有得到相同的结果。有人有什么建议吗?
I'm using this code to persist my ransack filters when the user destroys the item.
# In application controller
def get_query(cookie_key)
cookies.delete(cookie_key) if params[:clear]
cookies[cookie_key] = params[:q].to_json if params[:q]
@query = params[:q].presence || JSON.load(cookies[cookie_key])
end
# In my example controller
before_action only: [:index] do
get_query('example_capabilities')
end
def destroy
authorize @example
@example.destroy
respond_to do |format|
format.html { redirect_back fallback_location: get_query('example_capabilities'), notice: 'example was successfully destroyed.' }
format.json { head :no_content }
end
end
I'd like to use this when the user edit's the item as well but I am not getting the same results. Does anyone have any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论