mardi 24 février 2015

Rails multiple records select and apply multiple actions

I am quite new at rails and I am having some trouble designing an admin dashboard.


What I want to achieve is this:


Have a list of multiple users from database.


Have the ability to select multiple records.


Have the ability to apply different actions to all of the selected records.


The actions MAY not be directly translatable into SQL queries. (for example send an email)


I am not looking for a complete solution to the problem just a general description on how to approach this. I have a feeling I started on a wrong path.


So far I am doing this:


view



<%= form_tag("some_path", method: "get") do %>
<% @users.each do |user| %>
<%= check_box_tag "user_ids[]", users.id %>
<%end%>
<%end%>


controller



def send_email
@recipients = User.find(params[:user_ids])
@recipients.each do |recipient|
Notifier.raw_email(recipient.email, params[:user_email][:subject], params[:user_email][:body]).deliver
end
end


This works as it is but i can only apply one action, send email that is. I want to be able to choose an action to apply to all selected records or apply multiple actions to the selected records


Any thoughts?


Aucun commentaire:

Enregistrer un commentaire