我已创建了迁移t.boolean :published, :default =>false
如何使博客只能由管理员发布?
一个博客的模型,现在我不知道如何使这个博客帖子是在默认情况下,只有管理员可以发布取消发布。授权部分可以用cancan完成,模型和控制器如何?
这是我当前的代码: 型号/ blog.rb
class Blog < ActiveRecord::Base
attr_accessible :title, :content, :user_id, :published
has_many :comments, :as => :commentable
def published?
published
end
def published!
self.published = true
end
def unpublished!
self.published = false
end
end
控制器我使用make_resourceful插件来处理嵌套和多态
class BlogsController < ApplicationController
make_resourceful do
actions :all
response_for :create do
flash[:notice] = "Successfully created article."
redirect_to blogs_url
end
response_for :update do
flash[:notice] = "Successfully updated article."
redirect_to blogs_url
end
response_for :destroy do
flash[:notice] = "Successfully destroyed article."
redirect_to blogs_url
end
end
end
任何想法家伙/ blog_controller.rb# ??或者一个有用的链接?谢谢!
thnks为答复..然后如何显示只有:发布与真正被显示??我应该在def index上写什么? – Iqbal 2011-05-16 18:25:36
我想,我发现了适合我需要的插件.. https://github.com/mysmallidea/requires-approval – Iqbal 2011-05-16 18:48:37