Skip to content

Instantly share code, notes, and snippets.

@julioprotzek
Created March 4, 2014 10:32
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/9344008 to your computer and use it in GitHub Desktop.
Save julioprotzek/9344008 to your computer and use it in GitHub Desktop.
= simple_form_for(@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'
#= require jquery
#= require jquery_ujs
#= require bootstrap
#= require uploadbox
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
- if user_signed_in?
.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
li class="#{nav_status('users')}" = link_to 'Usuários', users_path
ul.nav.navbar-nav.pull-right
li = link_to current_user.name, edit_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 "application", "data-turbolinks-track" => true
@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
class Article < ActiveRecord::Base
validates :title, :category, :published_at, presence: true
belongs_to :category
uploads_one :image, thumb: [90, 80], small: [260, 195], regular: [580, 240], full: [1280, 493]
end
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
# 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, :image)
end
end
class CreateImages < ActiveRecord::Migration
def change
create_table :images do |t|
t.string :file
t.references :imageable, polymorphic: true, index: true
t.integer :width
t.integer :height
t.boolean :retina, default: false
t.string :upload_name
t.string :secure_random, index: true
t.timestamps
end
end
end
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.3.8'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 3.1.0'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '~> 2.2.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 1.2'
gem 'simple_form', '~> 3.0.1'
gem 'slim-rails', '~> 2.1.0'
gem 'xray-rails', '~> 0.1.12', group: :development
gem 'pry-rails', '~> 0.3.2', group: :development
gem 'start', '~> 0.1.1'
gem 'devise', '~> 3.2.2'
# upload
gem 'uploadbox', '0.1.3'
Paporeto::Application.routes.draw do
mount Uploadbox::Engine => '/uploadbox', as: :uploadbox
devise_for :users
resources :categories, except: :show
resources :articles
resources :users, except: :show
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
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
p = img @article.image.regular if @article.image?
= simple_format @article.body
Uploadbox.retina = true
Uploadbox.retina_quality = 30
Uploadbox.image_quality = 70
if Rails.env.production?
REDIS = Redis.connect(url: ENV["REDISCLOUD_URL"])
Resque.redis = REDIS
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['S3_KEY'],
aws_secret_access_key: ENV['S3_SECRET']
}
config.fog_directory = ENV['S3_BUCKET']
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
if Rails.env.test?
CarrierWave.configure do |config|
config.storage :file
config.enable_processing = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment