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.

    评论

报告相同问题?