刷新后退按钮上的所有信息按下:Ruby on Rails [英] Refresh All Information On Back Button Press: Ruby on Rails

查看:101
本文介绍了刷新后退按钮上的所有信息按下:Ruby on Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的RoR网站使用 fullcalendar gem来实现日历。每个用户都有一个日历,显示他或她参加的活动。以下场景为我的问题设置了舞台:


  1. 用户Alice在她的日历上单击一个事件,导致事件的 show 页面。

  2. Alice在事件的显示页面上点击'unattend event'按钮 / li>
  3. Alice点击后退按钮。

  4. 她只是无人看管的事件仍然列在她的日历中。

  5. ol>

    如何让浏览器刷新Alice的事件信息,以便仅当按下后退按钮时才显示她当前正在参加的事件?



    我搜索了Stack Overflow,但没有找到工作解决方案。缓存清除,如这里所见如何防止在Rails中浏览器页面缓存没有工作。我甚至不确定这是一个缓存问题。也许有一些JavaScript会强制信息被重新加载?任何解决方案都非常感谢。谢谢!



    回复@ElliottRoche:



    参与按钮在视图中点击,触发参与action:

     <%= button_to button_text,attend_event_path(@event),:remote => true,:id => 参加%> 

    参加活动按以下方式添加/删除与会者列表中的与会者:

      def参加

    @event = Event.find(params [:id])
    @attendee = User .find(session [:user_id])

    if @ event.users.exclude?(@ attendee)
    @ event.users<< @attendee
    @ event.save

    else
    @ event.users.delete(@attendee)
    end

    @attendees = @ event.users


    respond_to | format |
    format.js
    format.html {}
    format.json {}
    end
    end

    使用attend.js.erb,与会者列表将使用UJS进行更新:

     <$ c $(<%attendees_list',:locals => {:attendees => @attendees})%> $('#attendees-list')。 ); 

    从这里开始,当后退按钮被按下时,用户参加/无人参与事件不会被反映出来。

    解决方案

    尝试添加 format.html {redirect_to(@event) code>在响应块。


    My RoR website implements a calendar using the fullcalendar gem. Each user has a calendar that shows the events which he or she is attending. The following scenario sets the stage for my question:

    1. User Alice clicks an event on her calendar, which leads to the event's show page.
    2. Alice clicks the 'unattend event' button on the event's show page
    3. Alice clicks the back button.
    4. The event that she just unattended is still listed on her calendar.

    How can I make the browser refresh Alice's event information, so that only events that she is currently attending are displayed, when the back button is pressed?

    I've scoured Stack Overflow and not found a working solution. Cache clearing as seen here How to prevent browser page caching in Rails did not work. I'm not even sure this is a caching problem. Perhaps there is some javascript that will force information to be reloaded? Any solutions are much appreciated. Thanks!

    In response to @ElliottRoche:

    The attend button is clicked in the view, triggering the attend action:

    <%= button_to button_text, attend_event_path(@event), :remote => true,  :id => "attend" %>
    

    The attend action adds/removes the attendee from the list of attendees as follows:

     def attend
    
        @event = Event.find(params[:id])
        @attendee = User.find(session[:user_id])
    
        if @event.users.exclude?(@attendee)
          @event.users << @attendee
          @event.save
    
        else
          @event.users.delete(@attendee)
        end
    
        @attendees = @event.users
    
    
        respond_to do |format|
          format.js
          format.html {  }
          format.json { }
        end
    end
    

    With attend.js.erb, the attendees list is updated using UJS:

    $('#attendees-list').html("<%= j render(:partial => 'attendees_list', :locals => { :attendees => @attendees }) %>");
    

    From here, when the back-button is pressed, the fact that the user has attended/unattended the event is not reflected.

    解决方案

    Try adding format.html { redirect_to(@event) } in the respond to block.

    这篇关于刷新后退按钮上的所有信息按下:Ruby on Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆