How to create a controller and action without a model?

I have several models:

  • Email
  • Letter
  • Call

All three belong to the model campaign. And the has_many Contacts campaign

I guess I can see the schedule for Today by going to the domain / schedule / today

I would like it to show all the events (email, letter, call) that should happen today for each campaign.

I tried the following, but I have some problems with putting it in the controller and in the view. There are many letters in the campaign.

Email.days is the number of days from contact.start_date contact that an email should be sent to the contact.

ScheduleController < 

def index

   campaigns.each do |campaign| #goes through each campaign

      for contacts in campaign.contacts

         Email.find(:all).reject { |email| email.contact.start_date + email.days <= Date.now }


      end
   end

end
+3
source share
1

. - , , . FooController, DogController, .

:

  • "" - .
  • , ..

:

def index
  @campaigns = Campaign.all #share the list of campaigns with the view
end

.

<% for campaign in @campaigns %>
<!-- display info about the campaign -->

  <% for contacts in campaign.contacts %>
<!-- contact level info and so on.. -->

  <% end %>
<% end %>

, , , .

+5

Source: https://habr.com/ru/post/1743045/


All Articles