Skip to content

Commit

Permalink
Se movió la gestión de Posts al administrador
Browse files Browse the repository at this point in the history
  • Loading branch information
fcingolani committed Dec 8, 2011
1 parent bc92e17 commit e33b434
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def update
end

def create
create! do |success, failure|
create!(:notice => "Creado correctamente.") do |success, failure|
success.html { redirect_to edit_resource_url }
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/admin/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Admin
class PostsController < BaseController
has_scope :has_status
has_scope :lifo, :type => :boolean, :default => true
end
end
12 changes: 0 additions & 12 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,4 @@ def show
@comments = comments_collection.page(page).per(VenganzasDelPasado::Application.config.comments_per_page)
end

def edit
end

def update
if @post.update_attributes(params[:post])
flash[:notice] = "Successfully updated post."
redirect_to @post
else
render 'edit'
end
end

end
2 changes: 1 addition & 1 deletion app/views/admin/articles/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%td= article.id
%td= article.title
%td
=link_to "Permalink", article
=link_to "Permalink", article, :target => '_blank'
=link_to "Editar", edit_admin_article_path(article)
=link_to "Eliminar", admin_article_path(article), :method => :delete, :confirm => "¿Estás seguro?"

Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/base/_sidebar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
= link_to "Dashboard", admin_dashboard_path
%li
= link_to "Comentarios", admin_comments_path
%li
= link_to "Posts", admin_posts_path
%ul
%li= link_to "Crear Post", new_admin_post_path
%li
= link_to "Artículos", admin_articles_path
%ul
Expand Down
23 changes: 23 additions & 0 deletions app/views/admin/posts/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= alert_message_for(post)

= form_for [:admin, post], :html => { :class => 'form-stacked' } do |f|
%fieldset

- if post.persisted?
%legend
Editando Post ##{post.id}
- if post.persisted?
%small= link_to "Ver original", post, :target => '_blank'

.clearfix
= f.label :title
.input
= f.text_field :title, :class => 'xxlarge'
.clearfix
= f.label :content
.input
= f.text_area :content, :class => 'xxlarge'

.actions
= f.submit ( post.new_record? ? 'Publicar' : 'Guardar' ), :class => 'btn primary'
= link_to 'Cancelar', admin_posts_path, :class => 'btn'
3 changes: 3 additions & 0 deletions app/views/admin/posts/_pills.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%ul.pills
%li{:class=>active_if_current(:action => :index)}= link_to "Listar Todos", admin_posts_path
%li{:class=>active_if_current(:action => :new)}= link_to "Crear Nuevo", new_admin_post_path
7 changes: 7 additions & 0 deletions app/views/admin/posts/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- page_title("Editando Post")

%h2.fancy-title Administración de Posts

= render 'pills'

= render 'form', :post => @post
26 changes: 26 additions & 0 deletions app/views/admin/posts/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- page_title("Administración de Posts")

%h2.fancy-title= html_page_title

= render 'pills'

- if @posts.empty?
%p No se han encontrado posts
-else
%table
%thead
%tr
%th #
%th Título
%th
%tbody
- @posts.each do |post|
%tr
%td= post.id
%td= post.title
%td
=link_to "Permalink", post, :target => '_blank'
=link_to "Editar", edit_admin_post_path(post)
=link_to "Eliminar", admin_post_path(post), :method => :delete, :confirm => "¿Estás seguro?"

= paginate @posts
7 changes: 7 additions & 0 deletions app/views/admin/posts/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- page_title("Crear nuevo Post")

%h2.fancy-title Administración de Posts

= render 'pills'

= render 'form', :post => @post
4 changes: 2 additions & 2 deletions app/views/posts/_post.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Aún no hay información disponible sobre este programa.
- if can? :update, post
Colaborá con la comunidad
= link_to "editándolo", edit_post_path(post)
= link_to "editándolo", edit_admin_post_path(post)
- else
Colaborá con la comunidad,
= link_to "postulate a editor", '#'
Expand All @@ -27,4 +27,4 @@
= link_to post.comments.approved_or_from_user(current_user).count, post_path(post, :anchor => "comments")
%span.permalink=link_to "Permalink", post
- if can? :update, post
%span.edit= link_to "Editar", edit_post_path(post)
%span.edit= link_to "Editar", edit_admin_post_path(post)
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru', :as => :user_omniauth
end

resources :posts do
resources :posts, :only => [:index, :show] do
get 'page/:page', :action => :index, :on => :collection
get 'page/:page', :action => :show, :on => :member
resources :comments, :only => [:show, :create] do
Expand All @@ -27,6 +27,7 @@
end
end
resources :articles
resources :posts
end

root :to => 'home#index'
Expand Down

0 comments on commit e33b434

Please sign in to comment.