Created
March 10, 2014 22:58
-
-
Save julioprotzek/9476212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= require jquery | |
#= require jquery_ujs | |
#= require bootstrap | |
#= require uploadbox | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctype html | |
html | |
head | |
meta name="viewport" content="width=device-width, initial-scale=1.0" | |
title Paporeto | |
= stylesheet_link_tag "admin", 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 | |
- if user_signed_in? | |
.navbar.navbar-inverse.navbar-fixed-top | |
.container | |
.navbar-header | |
= link_to 'Paporeto', '#', class: 'navbar-brand' | |
.navbar-collapse | |
ul.nav.navbar-nav | |
li class="#{nav_status('articles')}" = link_to 'Artigos', admin_articles_path | |
li class="#{nav_status('categories')}" = link_to 'Categorias', admin_categories_path | |
li class="#{nav_status('users')}" = link_to 'Usuários', admin_users_path | |
ul.nav.navbar-nav.pull-right | |
li = link_to current_user.name, edit_admin_user_path(current_user) | |
li = link_to 'Sair', destroy_user_session_path, method: :delete | |
.container | |
- if notice | |
.alert.alert-info.alert-dismissable | |
button type="button" class="close" data-dismiss="alert" aria-hidden="true" × | |
= notice | |
= yield | |
= javascript_include_tag "admin", "data-turbolinks-track" => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "bootstrap" | |
@import "uploadbox" | |
body | |
margin: 60px 0 | |
textarea.form-control | |
height: 250px | |
select.form-control | |
width: 120px | |
display: inline-block | |
input[type="checkbox"].form-control | |
display: inline | |
width: auto | |
height: auto | |
padding: 0 | |
box-shadow: none | |
label.control-label | |
padding: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for([:admin, @article]) do |f| | |
= f.error_notification | |
.form-inputs | |
= f.uploads_one :image, preview: :regular | |
= f.input :title | |
= f.association :category, prompt: 'Selecione' | |
= f.input :body | |
= f.input :published_at | |
.form-actions | |
= f.button :submit, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Artigos | |
table.table.table-striped | |
thead | |
tr | |
th Título | |
th Publicado em | |
th Categoria | |
th | |
tbody | |
- @articles.each do |article| | |
tr | |
td = article.title | |
td = l article.published_at | |
td = article.category.name | |
td | |
.btn-group.pull-right | |
= link_to 'Ver', [:admin, article], class: 'btn btn-default btn-sm' | |
= link_to 'Editar', edit_admin_article_path(article), class: 'btn btn-default btn-sm' | |
= link_to 'Excluir', [:admin, article], :confirm => 'Tem certeza?', :method => :delete, class: 'btn btn-default btn-sm' | |
br | |
= link_to 'Criar Artigo', new_admin_article_path, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 | |
= @article.title | |
.pull-right | |
= link_to 'Editar', edit_admin_article_path(@article), class: 'btn btn-default' | |
hr | |
strong = @article.category.name | |
p = l @article.published_at | |
p = img @article.image.regular if @article.image? | |
= simple_format @article.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for([:admin, @category]) do |f| | |
= f.error_notification | |
.form-inputs | |
= f.input :name | |
.form-actions | |
= f.button :submit, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Categorias | |
table.table.table-striped | |
thead | |
tr | |
th Nome | |
th | |
tbody | |
- @categories.each do |category| | |
tr | |
td = category.name | |
td | |
.btn-group.pull-right | |
= link_to 'Editar', edit_admin_category_path(category), class: 'btn btn-default btn-sm' | |
= link_to 'Excluir', [:admin, category], :confirm => 'Tem certeza?', :method => :delete, class: 'btn btn-default btn-sm' | |
br | |
= link_to 'Nova Categoria', new_admin_category_path, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for([:admin, @user]) do |f| | |
= f.error_notification | |
.form-inputs | |
= f.input :name | |
= f.input :email | |
= f.input :password | |
= f.input :password_confirmation | |
.form-actions | |
= f.button :submit, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Usuários | |
table.table.table-striped | |
thead | |
tr | |
th Nome | |
th Email | |
th | |
tboby | |
- @users.each do |user| | |
tr | |
td = user.name | |
td = user.email | |
td | |
.btn-group.pull-right | |
= link_to 'Editar', edit_admin_user_path(user), class: 'btn btn-default btn-sm' | |
= link_to 'Excluir', [:admin, user], data: {:confirm => 'Tem certeza?'}, :method => :delete, class: 'btn btn-default btn-sm' | |
br | |
= link_to 'Criar usuário', new_admin_user_path, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= require jquery | |
#= require jquery_ujs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
.container | |
= yield | |
= javascript_include_tag "application", "data-turbolinks-track" => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "bootstrap" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::ArticlesController < ApplicationController | |
before_action :set_article, only: [:show, :edit, :update, :destroy] | |
before_action :authenticate_user! | |
layout 'admin' | |
# 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 [:admin, @article], notice: 'Artigo salvo.' | |
else | |
render action: 'new' | |
end | |
end | |
# PATCH/PUT /articles/1 | |
def update | |
if @article.update(article_params) | |
redirect_to [:admin, @article], notice: 'Artigo salvo.' | |
else | |
render action: 'edit' | |
end | |
end | |
# DELETE /articles/1 | |
def destroy | |
@article.destroy | |
redirect_to admin_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, :image) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::CategoriesController < ApplicationController | |
before_action :set_category, only: [:edit, :update, :destroy] | |
before_action :authenticate_user! | |
layout 'admin' | |
# 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 admin_categories_url | |
else | |
render action: 'new' | |
end | |
end | |
# PATCH/PUT /categories/1 | |
def update | |
if @category.update(category_params) | |
redirect_to admin_categories_url | |
else | |
render action: 'edit' | |
end | |
end | |
# DELETE /categories/1 | |
def destroy | |
@category.destroy | |
redirect_to admin_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Paporeto::Application.routes.draw do | |
mount Uploadbox::Engine => '/uploadbox', as: :uploadbox | |
devise_for :users | |
namespace :admin do | |
resources :categories, except: :show | |
resources :articles | |
resources :users, except: :show | |
root 'articles#index' | |
end | |
root 'home#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::UsersController < ApplicationController | |
before_action :set_user, only: [:edit, :update, :destroy] | |
before_action :authenticate_user! | |
layout 'admin' | |
# GET /users | |
def index | |
@users = User.all | |
end | |
# GET /users/new | |
def new | |
@user = User.new | |
end | |
# GET /users/1/edit | |
def edit | |
end | |
# POST /users | |
def create | |
@user = User.new(user_params) | |
if @user.save | |
redirect_to admin_users_url | |
else | |
render action: 'new' | |
end | |
end | |
# PATCH/PUT /users/1 | |
def update | |
if user_params[:password].blank? | |
@user.update_without_password(user_params_without_password) | |
else | |
@user.update(user_params) | |
end | |
if @user.valid? | |
if @user == current_user | |
sign_in(@user, bypass: true) | |
end | |
redirect_to admin_users_url | |
else | |
render action: 'edit' | |
end | |
end | |
# DELETE /users/1 | |
def destroy | |
@user.destroy | |
redirect_to admin_users_url, notice: 'Usuário excluído.' | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_user | |
@user = User.find(params[:id]) | |
end | |
# Only allow a trusted parameter "white list" through. | |
def user_params | |
params.require(:user).permit(:name, :email, :password, :password_confirmation) | |
end | |
def user_params_without_password | |
user_params.delete(:password) | |
user_params.delete(:password_confirmation) | |
user_params | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment