find_by_sql(custom_sql)
end
end
Save this file as app/controller/reporter_controller.rb.
Next, create the single view, as shown in Listing 11-4.
Listing 11-4. Reporter View (app/views/reporter/index.rhtml)
Our Company In The Media
<%
story_count_max = @stories.max { |a,b| a.count.to_i <=> b.count.to_i }.count.to_f
story_data = @stories.map{|x| ["#{x.published_at_formatted} (#{x.count})",
(x.count.to_f / story_count_max)*100]}
CHAPTER 11 n TRACKING THE NEWS WITH GOOGLE NEWS 229
%>
<%= complex_bar_graph story_data %>
Save this view as app/views/reporter/index.rhtml.
You don??™t need to add any code into your model file. The defaults are fine, since the
model doesn??™t need any relationships or other customizations. So, your application is
all set.
At this point, you??™ll need to edit the config/database.yml file with your database connection
parameters.
You can run this script using the following command:
ruby script/server
Now open a web browser and browse to http://localhost:3000/reporter/.
Pages:
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330