I am fairly new to Rails, and I am trying to use the jQuery newsticker from codecanyon to display the most recent event titles that have been entered into the database. Example here:
http://codecanyon.net/item/jnewsticker-jquery-news-ticker/full_screen_preview/2137525
Right now, it is showing every entry in the database, and also all rows in the events table, instead of just the title, and I think the script is choking on that.
I want it to only show the 10 most recent events.
In my events_helper.rb helper I have:
module EventsHelper
def populate_event
@events.each do |event|
content_tag(:li, link_to(event.title, '#'))
end
end
end
In my events_controller.rb controller I have:
class EventsController < ApplicationController
before_filter :signed_in_user
def create
@event = current_user.events.build(params[:event])
if @event.save
flash[:success] = "Event created!"
redirect_to root_url
else
render 'static_pages/home'
end
end
def destroy
end
def show
@event = Event.find(params[:id])
@events = Event.recent
end
end
In my event.rb model I have:
scope :recent, order(updated_at: 'DESC')
In my _ticker.html.erb partial I have
<ul id="newsticker_1" class="newsticker">
<%= populate_event %>
</ul>
When I look at the source code in the browser, there are no <li>
tags in the list.
It looks like this:
<ul id="newsticker_1" class="newsticker" style="position: absolute; left: 10px;">
[#<Event id: 29196, title: "This is a title", tag: nil, privacy_level: 1, group: nil, image_url: nil, start_date: nil, end_date: nil, start_location: nil, end_location: nil, start_geolocation: nil, end_geolocation: nil, content: "Quia officiis voluptatum doloribus cum ut ea sed ve...", user_id: 2, created_at: "2012-12-09 03:51:26", updated_at: "2012-12-09 03:51:26">, #<Event id: 29190, title: "This is a title", tag: nil, privacy_level: 1, group: nil, image_url: nil, start_date: nil, end_date: nil, start_location: nil, end_location: nil, start_geolocation: nil, end_geolocation: nil, content: "Dolor consequatur sed enim omnis asperiores fugit r...", user_id: 2, created_at: "2012-12-09 03:51:26", updated_at: "2012-12-09 03:51:26">
</ul>
It should look something like this:
<ul id="newsticker_1" class="newsticker">
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</li>
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip...</li>
<li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum...</li>
<li>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia...</li>
<li>Bubble bubble ipsum dolor sit amet, consectetur adipisicing elit...</ li>
</ul>
UPDATE:
Following the suggestion of Dimuch below
This is what the ticker looks like in the browser:
This is what the HTML source is doing: