ActiveAdmin.register Post do
permit_params :title, :content, :deadline, :status
menu parent: "论坛管理", label: "帖子管理", :priority => 2
config.per_page = 20
config.sort_order = "id_asc"
index :title=>"帖子管理" do
selectable_column
id_column
column "标题", :title
column "提交日期" do |f|
f.deadline ? f.deadline.strftime('%Y-%m-%d %H:%M:%S') : ""
end
column "用户" do |f|
link_to f.user.id, admin_user_path(f.user) if f.user
end
column "分类" do |f|
f.label ? f.label.name : ""
end
column "创建时间", :sortable=>:created_at do |f|
f.created_at.strftime('%Y-%m-%d %H:%M:%S')
end
actions
end
form do |f|
f.inputs "Post详情" do
f.input :title, :label => "标题"
end
f.inputs "额外信息" do
f.input :content, :label => "标题"
end
f.actions
end
show :title=>:title do
attributes_table do
row "操作" do
link_to("设置置顶", set_stick_admin_post_path(post.id)) + " " + link_to("取消置顶", clear_stick_admin_post_path(post.id))
end
end
end
#route当中无需任何配置
member_action :set_stick do
post = Post.find(params[:id])
post.update_attribute :status, Setting.posts.status_stick
redirect_to admin_post_path(params[:id])
end
member_action :clear_stick do
post = Post.find(params[:id])
post.update_attribute :status, Setting.posts.status_none
redirect_to admin_post_path(params[:id])
end
controller do def update update! do |f| puts permitted_params[:citrine][:count] f.html {redirect_to root_path} end end end
end