D
D
dexdev2014-11-15 02:26:54
Ruby on Rails
dexdev, 2014-11-15 02:26:54

How to make a link to bulk change columns in rails?

Hello everyone, there are notifications for users

<div class="notification">
  <h4>Уведомления</h4>
<% @activities.each do |activity| %>
    <ul>
    	<li>
    <%= render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity: activity %>
    	</li>
    </ul>
<% end %>
<%= link_to "отменить всё как прочитано"%>
</div>

It is necessary that when you click on "cancel everything as read", the read columns from false to true in the Activity base go to the database, please tell me how to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Renat Ibragimov, 2014-11-15
@MpaK999

1. we collect all id of these events into one array, for example activities[]
2. we send it via ajax serialize
3. we get this array in the controller

activities = Activity.find(params[:activities])
activities.each do |activity|
  activity.mark_as_read!
end

A
anyd3v, 2014-11-15
@anyd3v

apidock.com/rails/ActiveRecord/Relation/update_all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question