Skip to content

Commit 01601fd

Browse files
committed
Create draft
1 parent e988c17 commit 01601fd

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

app/controllers/admin/snippets_controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
class Admin::SnippetsController < Admin::BaseController
22
resource_controller
33

4+
def create_draft
5+
@snippet = Snippet.create!
6+
redirect_to edit_admin_snippet_url(@snippet.id)
7+
end
8+
49
update.response do |wants|
510
wants.html { redirect_to collection_url }
611
end

app/models/snippet.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
class Snippet < ActiveRecord::Base
2-
validates_presence_of :slug
3-
validates_uniqueness_of :slug
2+
validates_uniqueness_of :slug, :allow_blank => true
43
end

app/views/admin/snippets/_form.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
}
66
</style>
77

8-
<%= rich_editor(:id => 'snippet_content', :object => @snippet) %>
9-
108
<table class="admin-report" width="545">
119
<tr>
1210
<td valign="top"><%=t("snippets_slug")%>:</td>
@@ -27,3 +25,5 @@
2725
<a href="#"><%= t("editor.switch_rich") %></a>
2826
</div>
2927
</div>
28+
29+
<%= rich_editor(:id => 'snippet_content', :object => @snippet) %>

app/views/admin/snippets/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class='toolbar'>
44
<ul class='actions'>
55
<li id="new_product_link">
6-
<%= button_link_to t("new_snippet"), new_object_url, {:icon => 'add'} %>
6+
<%= button_link_to t("new_snippet"), create_draft_admin_snippets_url, {:icon => 'add'} %>
77
</li>
88
</ul>
99
<br class='clear' />

config/routes.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Rails.application.routes.draw do
22
namespace :admin do
3-
resources :snippets
3+
resources :snippets do
4+
collection do
5+
get :create_draft
6+
end
7+
end
48
end
59
end

0 commit comments

Comments
 (0)