Note that this project is not complete. If you would like to use it please consider forking the code and completing functionality.
Add a blog to any object.
Add the gem to your Gemfile:
gem "muck-blogs"
Installing the gem will also install dependencies. Specifically Muck Blogs requires Muck Contents. Be sure to properly configure your application for Muck Contents - github.com/tatemae/muck_contents/tree/master
Add ‘enable_post_activities’ to an initializer to determine whether or not an activity will be added after a user contributes a post. This requires that the application be configured to use Muck Activities.
MuckBlogs.configure do |config| enable_post_activities = true end
Create a model called blog in your project and add the following:
class Blog < ActiveRecord::Base include MuckBlogs::Models::MuckBlog end
This let’s you override or add other methods to the blog model that you see fit.
Muck Blogs requires Muck Contents. Be sure to setup Muck Content then add include MuckBlogs::Models::MuckPost to your Content model:
class Content < ActiveRecord::Base include MuckBlogs::Models::MuckPost # include MuckActivities::Models::MuckActivitySource # Include this if you wish to have entries added to activity feeds upon each new post end
Muck Blogs uses Muck Contents which requires that the user model have a method called ‘can_add_root_content?’. Add the following method to your user model and modify it according to your specific needs:
def can_add_root_content? admin? end
This method determines who can add content to any url on your website. For example, if you type in www.example.com/a/test/page and that page does not exist, muck contents will automatically create a page for you at that location if the logged in user has a method can_add_root_content? that returns true.
You’ll likely want to override some functionality in the blogs controller. Add a controller and inherit from Muck::BlogsController
# Route would be: # resources :blogs # resources :users do # resources :blogs # end class BlogsController < Muck::BlogsController end
OR
# Route looks like this: # resources :users do # resource :blog do # resources :posts # end # end class User::BlogsController < Muck::BlogsController end
Add a posts controller:
# Route would be: # resources :posts # resources :users :has_many => [:blogs] class PostsController < Muck::ContentsController end # Route looks like this: # resources :users do # resource :posts # resource :blog do # resources :posts # end # end class Users::PostsController < Muck::ContentsController end
If you chose to not override either controller you can setup routes like this to attach a blog to your models:
resources :users do resource :blog, :controller => 'muck/blogs' resources :posts, :controller => 'muck/posts' end end
For a given model add ‘include MuckBlogs::Models::MuckBloggable’
class User < ActiveRecord::Base include MuckBlogs::Models::MuckBloggable end users.resource :blog, :controller => 'muck/blogs' do |blogs|
Copyright © 2009-2010 Tatemae.com released under the MIT license