-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
! Adding column status to posts table.Adding scope to Post index page…
…. Customze the Show page.Adding Dashboard sections.
- Loading branch information
Showing
6 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
ActiveAdmin.register Post do | ||
scope :all, :default => true | ||
Post::STATUS.each do |status| | ||
scope status.to_sym do |posts| | ||
posts.where("status = ?", status) | ||
end | ||
end | ||
|
||
form do |f| | ||
f.inputs "New Post" do | ||
f.input :title | ||
f.input :status, :as => :select, :collection => Post::STATUS | ||
f.input :category | ||
f.input :body | ||
f.buttons | ||
end | ||
end | ||
|
||
index do | ||
column :title | ||
default_actions | ||
end | ||
|
||
show do |post| | ||
attributes_table do | ||
row :title | ||
row :category | ||
row :status do |post| | ||
status_tag post.status, (post.status == "Published" ? :ok : :warning) | ||
end | ||
row :body | ||
end | ||
active_admin_comments | ||
end | ||
|
||
sidebar "Other Post for this Category", :only => :show do | ||
ul do | ||
Post.where("id IS NOT ? AND category_id = ?", resource.id, resource.category.id).each do |post| | ||
li link_to post.title, admin_post_path(post) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Category < ActiveRecord::Base | ||
attr_accessible :name | ||
validates :name, :presence => true | ||
has_many :posts | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class Post < ActiveRecord::Base | ||
attr_accessible :body, :title, :category_id | ||
STATUS = %w(Draft Published) | ||
attr_accessible :body, :title, :category_id, :status | ||
validates :title, :body, :presence => true | ||
validates :status, :inclusion => { :in => self::STATUS } | ||
belongs_to :category | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStatusToPosts < ActiveRecord::Migration | ||
def change | ||
add_column :posts, :status, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters