Skip to content
This repository was archived by the owner on Nov 12, 2021. It is now read-only.

Commit 93eafb1

Browse files
committed
ActiveAdminEditor
1 parent 2a6f3a1 commit 93eafb1

File tree

11 files changed

+46
-7
lines changed

11 files changed

+46
-7
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ gem 'jquery-rails', "2.3.0"
2424
gem 'activeadmin'
2525
gem 'meta_search'
2626
gem 'gravtastic'
27+
gem 'active_admin_editor'
28+
2729

2830
# To use ActiveModel has_secure_password
2931
# gem 'bcrypt-ruby', '~> 3.0.0'

Gemfile.lock

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ GEM
1414
rack-cache (~> 1.2)
1515
rack-test (~> 0.6.1)
1616
sprockets (~> 2.2.1)
17+
active_admin_editor (1.1.0)
18+
activeadmin (>= 0.4.0)
19+
ejs
20+
rails (>= 3.0.0)
1721
activeadmin (0.6.0)
1822
arbre (>= 1.0.1)
1923
bourbon (>= 1.0.0)
@@ -62,6 +66,7 @@ GEM
6266
railties (>= 3.2.6, < 5)
6367
thread_safe (~> 0.1)
6468
warden (~> 1.2.3)
69+
ejs (1.1.1)
6570
erubis (2.7.0)
6671
execjs (2.0.0)
6772
fastercsv (1.5.5)
@@ -95,7 +100,6 @@ GEM
95100
mime-types (1.24)
96101
multi_json (1.8.0)
97102
orm_adapter (0.4.0)
98-
pg (0.12.2)
99103
pg (0.12.2-x86-mingw32)
100104
polyamorous (0.5.0)
101105
activerecord (~> 3.0)
@@ -155,6 +159,7 @@ PLATFORMS
155159
x86-mingw32
156160

157161
DEPENDENCIES
162+
active_admin_editor
158163
activeadmin
159164
coffee-rails (~> 3.2.1)
160165
gravtastic

app/admin/posts.rb

+9
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,13 @@
77
column :created_at
88
default_actions
99
end
10+
11+
form do |f|
12+
f.inputs do
13+
f.input :title
14+
f.input :body, as: :html_editor
15+
end
16+
17+
f.buttons
18+
end
1019
end

app/assets/stylesheets/active_admin.css.scss

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@import "active_admin/mixins";
1212
@import "active_admin/base";
1313

14+
1415
// Overriding any non-variable SASS must be done after the fact.
1516
// For example, to change the default status-tag color:
1617
//

app/assets/stylesheets/application.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*= require_self
1212
*/
13-
13+
//= require active_admin/editor/wysiwyg
1414

1515
body {
1616
margin: 0;

app/controllers/posts_controller.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ def index
44
#@content_first = 'This is some sample text for the SuckerPunched Webapp';
55
#@content_second = 'This is some more sample text';
66
@posts = @search.all
7+
8+
respond_to do |format|
9+
format.html # index.html.erb
10+
format.json { render json: @posts }
11+
format.atom
12+
end
713
end
814

915
def new
@@ -37,11 +43,17 @@ def show
3743
@post = Post.find(params[:id])
3844
@user = AdminUser.all
3945
@post_comment = PostComment.new(:post => @post)
46+
47+
respond_to do |format|
48+
format.html
49+
format.json { render json: @post }
50+
end
51+
4052
end
4153

4254
def destroy
4355
@post = Post.find(params[:id])
4456
@post.destroy
45-
redirect_to posts_path, :notice => "Your Post will incinerated shortly."
57+
redirect_to posts_path, :notice => "Your Post will be incinerated shortly."
4658
end
4759
end

app/models/post.rb

+5
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ class Post < ActiveRecord::Base
33
belongs_to :category
44
belongs_to :admin_user
55
has_many :post_comments, :dependent => :destroy
6+
7+
def content
8+
markdownService.new.render(body)
9+
end
10+
611
end

app/views/categories/show.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="byline">
66
<p class="meta">May 07, 2012 Posted by <%= post.admin_user.name %></p>
77

8-
<p class="links"><%= link_to "Read More",post %>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<%= link_to "Comments",@post_comment.post %></p>
8+
<p class="links"><%= link_to "Read More",post %>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<%= link_to "Comments",post %></p>
99
</div>
1010
</div>
1111
<% end.empty? %>

app/views/posts/show.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h1><%= @post.title %></h1>
33
<small><%= @post.created_at.strftime("%b %d. %Y") %></small>
44
<p>Fabricated by: <%= @post.admin_user.name %></p>
5-
<p><%= @post.body %></p>
5+
<p><%= @post.content.html_safe %></p>
66
<p>Category: <%= link_to @post.category.name,categories_path(:id => @post.category.id) %></p>
77
<p><%= link_to "Back",posts_path %></p>
88

config/initializers/active_admin.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,5 @@
205205
# You can enable or disable them for all resources here.
206206
#
207207
# config.filters = true
208-
209-
208+
210209
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ActiveAdmin::Editor.configure do |config|
2+
# config.s3_bucket = ''
3+
# config.aws_access_key_id = ''
4+
# config.aws_access_secret = ''
5+
# config.storage_dir = 'uploads'
6+
end

0 commit comments

Comments
 (0)