Tim*_* T. 3 for-loop controller ruby-on-rails
我有几个型号:
这三个都属于模特运动.一个广告系列有很多联系人
我设想能够通过今天访问域/日程表来查看今天的日程安排
我希望它能够显示今天必须为每个广告系列发生的所有活动(电子邮件,信函,电话).
我尝试了以下方法,但在将其放入控制器而不是View中时遇到了一些挑战.广告系列中有很多电子邮件.
Email.days是contact.start_date应将电子邮件发送给联系人的天数.
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
Run Code Online (Sandbox Code Playgroud)
你实际上是在问错误的问题.控制器没有从根本上与任何模型相关联,它们真正显示你想要的任何东西.你可以有一个显示所有Bars的FooController和一个提供有关猫的信息的DogController.
要解决您的问题:
在您的控制器中,您需要从数据库中获取数据:
def index
@campaigns = Campaign.all #share the list of campaigns with the view
end
Run Code Online (Sandbox Code Playgroud)
在您的视图中,您会显示广告系列信息..
<% for campaign in @campaigns %>
<!-- display info about the campaign -->
<% for contacts in campaign.contacts %>
<!-- contact level info and so on.. -->
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
还有更多,但希望这会让你指向正确的方向.
| 归档时间: |
|
| 查看次数: |
4287 次 |
| 最近记录: |