weixin_33720078 2015-10-19 14:14 采纳率: 0%
浏览 31

将部分附加到视图上

I currently have a partial being rendered via a click and an ajax call. The partial gets rendered at the top of the page, however on refresh the partial goes away(which is expected). I am wondering if there is anyway to have this partial append to the view after the button is clicked and it is rendered for the first time. I don't really want to create a db field checking to see if it has been clicked.

Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • lrony* 2015-10-19 14:32
    关注

    You need to think about the sequence of events here.

    • user makes request 1 to server
    • page 1 is rendered out
    • user makes ajax call to server
    • partial is added to page
    • user makes request 2 to server
    • page 2 is rendered out.

    AT THIS LAST POINT, rails needs to "decide" to add the partial on. It can base its decision on a few different things:

    • something in the database, eg in the user's preferences
    • a cookie
    • something in the session (possibly set via a previous form submission)
    • something in params

    You can decide which of these is the best option. Cookies feel like the best way, as they can be set in the client or the server, when that partial is added to the previous page. I guess your choice might depend on how permanent you want this change to be.

    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名