Reputation: 1617
so I've created a web app that has user profiles, where users can search for fellow users based on interests, and create events etc.. How might I add a feature on the events page that says 'interesting people' and randomly shows the profile_image of 5 users, and changes on every refresh.
_event.html.erb
div id="event_<%= event.id %>">
<div class="span2">
<% if event.user.profile_image.present? %>
<%= image_tag event.user.profile_image_url(:thumb), class: 'img-polaroid' %>
<% else %>
<%= image_tag "profile-placeholder1.png" %>
<% end %>
</div>
<div class="span3">
<div class="line2">
<h5><%= link_to_event_owner(event.user) %> Created an Event</h5>
<h4><%= link_to event.title, event %></h4>
<h5><i class="fa fa-map-marker"></i> <%= event.location %></h5>
<h5><i class="fa fa-calendar-o"></i> <%= event.date.strftime("%A, %B %d, %Y") %></h5>
<h5><i class="fa fa-clock-o"></i> <%= event.time %></h5>
<i class="fa fa-dot-circle-o"></i> <medium><strong align-"center"><%= pluralize(event.participants.size.to_s, 'person') %></strong></medium> <br /><br />
<% event.participants.each do |p| %>
<%= simple_user_avatar(p) %>
<%= p.short_name %> is attending.
<% end %>
</div>
</div>
</div>
<div class="clearfix"></div>
<p></p>
Upvotes: 0
Views: 102
Reputation: 1814
You can accomplish this by doing the following:
In the controller event that renders _event.html.erb (e.g, show) do something like this
def show @event = Event.find(params[:id]) # get 5 random attendees. I don't know about your model so this is just an example. #You could very well search other model. For example, People.order("RAND()").first(5).. @intersting_people = @event.attendees.order("RAND()").first(5) end
Then in your view loop through @intersting_people and display
<% @interesting_people.each do |person| %>
<%= person.first_name %>
<% end %>
That's just an example of what you could do. Good luck!
Upvotes: 1