Notes posted by concept47
RSS feedexpires_in option
You can actually pass in an expires_in option that sets how long Rails should show the fragment before deleting it so as an example …
<% cache('homepage_sidebar', :expires_in => 10.minutes) do %> <div> ... </div> <% end %>
This only used to work with memcached but it now works with other types of Rails stores, MemoryStore, FileStore (had to use a plugin to get this behavior before) etc etc
So in your controller. You’d just do …
@posts = Posts.all if fragment_exists?('homepage_sidebar')
to avoid performing a pointless SQL query.
use validates :name, :presence => true instead
validates_presence_of is a holdover from the Rails 2 days.
This is the way it is done now http://guides.rubyonrails.org/active_record_validations_callbacks.html#presence
be aware that this writes to tmp/cache
Its supposed to be http caching, but Rails will actually cache the response to whatever you specified as the cache store, *as well*, but only if you specify :public => true. The default is filestore so it will try to write to tmp/cache.
Only a problem if you don’t have the proper permissions set, in that scenario your apache/nginx logs could fill up very quickly with “permission denied errors”
Full explanation is here http://blog.tonycode.com/archives/418
link to nothing if link_to_if condition is false
When the link_to_if condition is false you can get this helper to display nothing by doing something like this
<%= link_to_if(message.user, 'Poster', message.user){} %>
^ That will display nothing if message.user does not exist.