我是铁杆初学者.我在通知控制器中使用after_action.
通知控制器
class NotificationsController < ApplicationController layout "posts" after_action :read_message, only: [:index] def index @notifications = Notification.where(:recipient_id => session[:registered_id]).order("created_at DESC") end def new @user = User.find(session[:user_id]) @notification = @user.notifications.new end def create @user = User.find(session[:user_id]) @notification = @user.notifications.new notification_params if @notification.save redirect_to(:controller => "posts", :action => "index") else render "new" end end private def notification_params params.require(:notification).permit(:message, :user_id, :recipient_id, :status) end def read_message @notifications = Notification.where(:recipient_id => session[:registered_id]).order("created_at DESC") @notifications.read_all end end
通知#index视图
<% @notifications.each do |notification| %><% end %><%= notification.message %>
from <%= notification.user.registered_id %>
现在在控制器的after_action方法中,我想将
在控制器中定义类名并不好.它应该适用于视图或帮助程序.
你只能这样做,
推荐阅读
如何解决《R中的"累积差异"功能》经验,为你挑选了1个好方法。 ... [详细] 如何解决《在Scala中使用带有Int的"或"运算符》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何将控制台C#应用程序添加到ASP.NETWebSite?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何在C中检测ESC键?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《为什么我的Stack实现中的第98个元素如此奇怪?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《嵌套异常的正确方法是什么?-使用Delphi》经验,为你挑选了2个好方法。 ... [详细] 如何解决《无法使用gradle创建RPM》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何使用Javascript将具有相同名称的对象分组?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《在for循环中追加一个列表?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《ReactNativePasswordTextInput抛出警告》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何从ActionBar中删除顶部边框阴影》经验,为你挑选了1个好方法。 ... [详细] 如何解决《使用boost::function和boost::bind》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何从<script>执行webpack模块?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何在Elixir中使用"with"关键字,它的用途是什么?》经验,为你挑选了2个好方法。 ... [详细] 如何解决《SceneKit,CIFilter.CICategoryBlur过滤任何可见的内容》经验,为你挑选了0个好方法。 ... [详细] 如何解决《在多台计算机中同步VirtualEnvs》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Javascript,基本关联数组》经验,为你挑选了1个好方法。 ... [详细] 如何解决《跳过前nn个字符,其余则使用RegEx》经验,为你挑选了1个好方法。 ... [详细] 如何解决《在Elastisearch中实施电子邮件提醒的最佳方式是什么?》经验,为你挑选了0个好方法。 ... [详细] 如何解决《在Phaser中循环播放音频》经验,为你挑选了1个好方法。 ... [详细]吐了个 "CAO" !Tags | 热门标签RankList | 热门文章
- 1查看kubernetes中崩溃的pod的日志文件
- 2从导航堆栈中删除页面 - xamarin.forms
- 3Visual Studio代码,MAC OS X,OmniSharp服务器未运行
- 4Bootstrap Datepicker未加载
- 5架构的重复符号x86_64从CocoaPods添加pod时
- 6如何在实现接口但不扩展另一个类的Java类中引用super方法?
- 7"git无法读取当前工作目录没有错误" - posh git(windows 10)
- 8我可以让nodejs --debug标志等待远程连接
- 9CakePHP 3 QueryBuilder:少数值的条件不会生成'IN'语句
- 10lxml无法解析xml(其他编码是否为utf-8)[python]
- 11移动 - iOS - Safari - window.outerHeight返回0
- 12将NodeJS部署到Elastic Beanstalk时出现NPM错误
- 13akka:如何测试一个演员被停止了
- 14为什么java只允许动态链接?
- 15声纳抱怨“ SonarQube分析已经在进行中”
- 16管道操作员如何在最后一行返回结果?
- 17Android:状态栏颜色更改,API级别低于21
- 18我可以提交MVC6视图组件吗?
- 19扩展RepositoryRestExceptionHandler
- 20MongoDB TimeZone
DevBox开发工具箱 | 专业的在线开发工具网站 京公网安备 11010802040832号 | 京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有