Skip to content

Commit

Permalink
Create draft
Browse files Browse the repository at this point in the history
  • Loading branch information
divineforest committed Dec 20, 2010
1 parent e988c17 commit 01601fd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/snippets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class Admin::SnippetsController < Admin::BaseController
resource_controller

def create_draft
@snippet = Snippet.create!
redirect_to edit_admin_snippet_url(@snippet.id)
end

update.response do |wants|
wants.html { redirect_to collection_url }
end
Expand Down
3 changes: 1 addition & 2 deletions app/models/snippet.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class Snippet < ActiveRecord::Base
validates_presence_of :slug
validates_uniqueness_of :slug
validates_uniqueness_of :slug, :allow_blank => true
end
4 changes: 2 additions & 2 deletions app/views/admin/snippets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
}
</style>

<%= rich_editor(:id => 'snippet_content', :object => @snippet) %>

<table class="admin-report" width="545">
<tr>
<td valign="top"><%=t("snippets_slug")%>:</td>
Expand All @@ -27,3 +25,5 @@
<a href="#"><%= t("editor.switch_rich") %></a>
</div>
</div>

<%= rich_editor(:id => 'snippet_content', :object => @snippet) %>
2 changes: 1 addition & 1 deletion app/views/admin/snippets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class='toolbar'>
<ul class='actions'>
<li id="new_product_link">
<%= button_link_to t("new_snippet"), new_object_url, {:icon => 'add'} %>
<%= button_link_to t("new_snippet"), create_draft_admin_snippets_url, {:icon => 'add'} %>
</li>
</ul>
<br class='clear' />
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Rails.application.routes.draw do
namespace :admin do
resources :snippets
resources :snippets do
collection do
get :create_draft
end
end
end
end

0 comments on commit 01601fd

Please sign in to comment.