Written by Robin Fisher in 252 words
As part of the home page on captured sparks, I wanted to have a “Recent Reads” section where I could list the articles that have caught my attention recently. I do most of my reading in Google Reader and thought that the Shared Items feature in Reader would be perfect for this. Thanks to the FeedTools gem, adding this was straightforward.
Firstly, grab the FeedTools gem, using sudo if necessary:
gem install feedtools
The way I added this function was to use a helper method inside my home_helper.rb call shared_items. Firstly require the gem in the head of the helper:
gem 'feedtools'
require 'feed_tools'
Setting up the method now looks like:
content = ''
days = 15
time = Time.now.utc - (86400 * days.to_i)
share_url = 'http://www.google.com/reader/public/atom/user/13411963057092720812/state/com.google/broadcast'
To create the shared item list:
feed = FeedTools::Feed.open(share_url)
feed.entries.each do |entry|
if entry.published > time
content << " <li>\n"
content << " <a href='#{entry.link}'>#{entry.title}</a>\n"
content << " <p />#{entry.find_node("source/title/text()").to_s}\n"
content << " </li>\n"
end
end
Finally, check to see if anything is shared and add the appropriate HTML container (or witty comment if nothing is shared), then return the content.
if content.length > 0
content = "<ul>" + content
content << "</ul>\n"
else
content = "<p />Not read anything of interest recently."
end
return content
The helper method is then called in the view by simply adding:
<%= shared_items %>
You can read more about FeedTools in the FeedTools API.
Written by Robin Fisher in 121 words
Just as I shut the laptop last night to go to bed, I came up with a solution to my leading slash problem.
attachment_fu’s default behaviour is to partition the directories into which it stores files based on id. In my case, my images were being placed into the folder public/images/0000/#{id}.
As such, I amended my deploy.rb file to read:
task :after_update_code, :roles => :app do
%w{0000}.each do |share|
run "rm -rf #{release_path}/public/images/#{share}"
run "mkdir -p #{shared_path}/system/images/#{share}"
run "ln -s #{shared_path}/system/images/#{share} #{release_path}/public/images/#{share}"
end
end
This symlinked the 0000 directory to an identically named directory in the shared part of the system.
I’ve deployed a couple of times since then and my images are still accessible.
Written by Robin Fisher in 77 words
It occurred to me late last night that due to my use of Capistrano to deploy sparky, any images that were uploaded were getting lost every time I deployed.
Thanks to a great article at almost effortless, I thought I had the problem solved.
Unfortunately, attachment_fu seems insistent on adding leading slashes, leading directories and all manner of things to the public_filename path. As such, all my images have disappeared until such time as I can fix this.
Written by Robin Fisher in 29 words
Would I have swapped the struggles of the last few days in terms of getting this up and running for the simplicity of Heroku?
I’m not sure that I would.
Written by Robin Fisher in 146 words
This inaugural post comes after several days of arguing with Ubuntu, Apache and Mongrel.
This site is hosted on a 256 slice from Slicehost and I’ve learnt a lot about Apache configuration, working with Linux and am now intimately familiar with the command line.
During the process, I’ve been helped by a significant number of resources that are out there and I intend to run a series of posts on how I got this site up and running in the hope that I may stand on the shoulders of giants and provide some insight of my own.
As a side note, you might have seen that this site is running on “sparky”. This is a custom built CMS coded in Rails that is very much in version 0.1. I’ll be doing some posts on its development as well as walking through some features as I add them.