Skip to content

Instantly share code, notes, and snippets.

@julioprotzek
Created January 20, 2014 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julioprotzek/8527268 to your computer and use it in GitHub Desktop.
Save julioprotzek/8527268 to your computer and use it in GitHub Desktop.
doctype html
html
head
meta name="viewport" content="width=device-width, initial-scale=1.0"
title Paporeto
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag "html5shiv", "data-turbolinks-track" => true
= javascript_include_tag "respond.min", "data-turbolinks-track" => true
body
.navbar.navbar-inverse.navbar-fixed-top
.container
.navbar-header
= link_to 'Paporeto', root_path, class: 'navbar-brand'
.navbar-collapse
ul.nav.navbar-nav
li class="#{nav_status('articles')}" = link_to 'Artigos', articles_path
li class="#{nav_status('categories')}" = link_to 'Categorias', categories_path
.container
.pull-right = today
h3 = maybe_friday
= yield
= javascript_include_tag "application", "data-turbolinks-track" => true
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
# GET /articles
def index
@articles = Article.order(published_at: :desc).order(:title)
end
# GET /articles/1
def show
end
# GET /articles/new
def new
@article = Article.new
end
# GET /articles/1/edit
def edit
end
# POST /articles
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article, notice: 'Artigo salvo.'
else
render action: 'new'
end
end
# PATCH/PUT /articles/1
def update
if @article.update(article_params)
redirect_to @article, notice: 'Artigo salvo.'
else
render action: 'edit'
end
end
# DELETE /articles/1
def destroy
@article.destroy
redirect_to articles_url, notice: 'Artigo excluído.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_article
@article = Article.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def article_params
params.require(:article).permit(:title, :body, :published_at, :category_id)
end
end
class CategoriesController < ApplicationController
before_action :set_category, only: [:edit, :update, :destroy]
# GET /categories
def index
@categories = Category.all
end
# GET /categories/new
def new
@category = Category.new
end
# GET /categories/1/edit
def edit
end
# POST /categories
def create
@category = Category.new(category_params)
if @category.save
redirect_to categories_url
else
render action: 'new'
end
end
# PATCH/PUT /categories/1
def update
if @category.update(category_params)
redirect_to categories_url
else
render action: 'edit'
end
end
# DELETE /categories/1
def destroy
@category.destroy
redirect_to categories_url, notice: 'Category was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_category
@category = Category.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def category_params
params.require(:category).permit(:name)
end
end
Paporeto::Application.routes.draw do
resources :categories, except: :show
resources :articles
root 'articles#index'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
- if notice
.alert.alert-info.alert-dismissable
button type="button" class="close" data-dismiss="alert" aria-hidden="true" &times;
= notice
h1
= @article.title
.pull-right
= link_to 'Editar', edit_article_path(@article), class: 'btn btn-default'
hr
strong = @article.category.name
p = l @article.published_at
= simple_format @article.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment