Ruby on rails Rails 3工具栏渲染
在我的网站工具栏中,我想用红色圆圈显示未读邮件的数量 因此,我认为最好的方法是在ApplicationController中创建一个名为update\u notification的方法:Ruby on rails Rails 3工具栏渲染,ruby-on-rails,ruby-on-rails-3,render,Ruby On Rails,Ruby On Rails 3,Render,在我的网站工具栏中,我想用红色圆圈显示未读邮件的数量 因此,我认为最好的方法是在ApplicationController中创建一个名为update\u notification的方法: def update_notification @notification = 42 # 42 is just for test end 在application.html.erb中,我显示: <%= render :partial => 'messages/noti
def update_notification
@notification = 42
# 42 is just for test
end
在application.html.erb中,我显示:
<%= render :partial => 'messages/notification' %>
“消息/通知”%>
_notification.html.erb:
<div id="notification">
<%= @notification %>
</div>
问题是何时何地可以调用update\u通知方法(在ApplicationController中?),您认为这样做是最好的方法吗
谢谢我认为最好的方法是定期使用
呼叫遥控器
:
<%= periodically_call_remote(:url => { :action => 'update_notification' }) %>
并在控制器中渲染它:
render :action => "update_notification.rjs"
before\u filter
是您需要的。将此添加到ApplicationController:
before_filter :update_notification
并且在每次操作之前都会调用您的方法。谢谢:)我认为这是最好的方法如何从更新通知方法调用包含“page.replace\u html”的rjs?
before_filter :update_notification