ver las categorias de un post y poder filtrar

This commit is contained in:
f 2018-02-19 18:16:48 -03:00
parent e90e20a901
commit 3a8c004ec7
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
3 changed files with 10 additions and 4 deletions

View file

@ -3,6 +3,7 @@ class PostsController < ApplicationController
def index def index
@site = find_site @site = find_site
@category = session[:category] = params.dig(:category)
end end
def show def show
@ -39,7 +40,7 @@ class PostsController < ApplicationController
@post.update_attributes(p) @post.update_attributes(p)
if @post.save if @post.save
redirect_to site_post_path(@site, @post) redirect_to site_posts_path(@site, category: session[:category])
else else
render 'posts/edit' render 'posts/edit'
end end

View file

@ -1,6 +1,6 @@
%nav{'aria-label': 'breadcrumb', role: 'navigation'} %nav{'aria-label': 'breadcrumb', role: 'navigation'}
%ol.breadcrumb %ol.breadcrumb
- crumbs.each do |crumb| - crumbs.compact.each do |crumb|
- if crumb == crumbs.last - if crumb == crumbs.last
%li.breadcrumb-item.active{'aria-current': 'page'}= crumb %li.breadcrumb-item.active{'aria-current': 'page'}= crumb
- else - else

View file

@ -1,6 +1,6 @@
.row .row
.col .col
= render 'layouts/breadcrumb', crumbs: [ link_to(t('sites.index'), sites_path), @site.name, t('posts.index') ] = render 'layouts/breadcrumb', crumbs: [ link_to(t('sites.index'), sites_path), @site.name, link_to(t('posts.index'), site_posts_path(@site)), @category ]
.row .row
.col .col
%h1= @site.name %h1= @site.name
@ -15,10 +15,15 @@
%table.table.table-condensed.table-striped %table.table.table-condensed.table-striped
%tbody %tbody
- @site.posts.each do |post| - @site.posts.each do |post|
- if @category
- next unless post.categories.include?(@category)
- direction = post.get_front_matter(:dir) - direction = post.get_front_matter(:dir)
%tr %tr
%td{class: direction} %td{class: direction}
= link_to post.title, site_post_path(@site, post) = link_to post.title, site_post_path(@site, post)
%br %br
%small= post.categories.join(', ') %small
- post.categories.each do |c|
= link_to c, site_posts_path(@site, category: c)
%td= post.date.strftime('%F') %td= post.date.strftime('%F')
%td= link_to t('post.edit'), edit_site_post_path(@site, post)