10 months ago
This is all over the internets but I'm sick of always having to search for it, so...
comments
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = Logger.new(STDOUT)
map.resources :posts do |post| post.resources :comments, :only => [:index, :create] end
it "should not allow update" do
lambda {put :update, :id => @com.id}.should raise_error(ActionController::RoutingError)
end
ActionController::Base.cache_store = :mem_cache_store, "ip_address_of_memcached_server",
{:namespace => "my_super_app"}
class PostsController < ApplicationController
cache_action :posts_with_comments
def posts_with_comments
# shows all posts with comments
end
end
class PostCommentSweeper < ActionController::Caching::Sweeper
observe Post, Comment
def after_save(rec)
expire_cache_for(rec)
end
def after_destroy(rec)
expire_cache_for(rec)
end
private
def expire_cache_for(rec)
expire_action(:controller => '/posts', :action => 'posts_with_comments')
end
end
Note: the '/' in the controller name is important if you will invoke the sweeper from a nested controller. Without the '/' the cache_key will be wrong and rails will not find your data in the cache.
cache_sweeper :post_comment_sweeper
cache_sweeper to.
Post.last.save in script/console.
CONFIG_PATH = RAILS_ENV == 'development' ?
"#{RAILS_ROOT}/config/amazon_s3_dev.yml" : nil
has_attachment :s3_config_path => CONFIG_PATH,
:storage => :s3,
.......
amazon_s3_dev.yml otherwise into the default file amazon_s3.yml.
amazon_s3_dev.yml-file should then look sth. like this:
development: bucket_name: social_dev_your_name access_key_id: your_access_key_id secret_access_key: your_secret_access_keyYou can now also remove the development entry from
amazon_s3.yml.
./script/console [development|test|staging]:
con = ActiveRecord::Base.connection
(con.tables-['schema_migrations', 'sessions']).each do |tbl|
con.execute "delete from #{tbl}"
end
schema_migrations and sessions table).
tbl.classify.constantize won't work if tbl is 'users_roles' for example (unless you created a class for this table of course).
class UsersRole < ActiveRecord::Base ; end