Skip to content

tatemae/muck-blogs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Muck Blogs

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.

Setup

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

Usage

Configuration

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

Blog model

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.

Content model

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

User model

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.

Blog Controller

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

Posts Controller

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

Default Routing

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

Attach blogs to a model:

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

About

Blogs for muck

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages