I am beginner in rails. I am using after_action in the notifications controller.
Notifications controller
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
notifications#index view
<% @notifications.each do |notification| %>
<div class = message_wrapper>
<p><%= notification.message %></p>
<p class = "message_details">from <span><%= notification.user.registered_id %></span></p>
</div>
<% end %>
Now in the after_action method in the controller, i want to set the class of <div>(currently with class message_wrapper) to message_wrapper_read. How can I do this? I appreciate your answers. Thanks in advance.