# HG changeset patch # User Edho Arief # Date 1346005703 25200 # Node ID 42de15334db14e91152312a7d669f4fdf9506755 # Parent 49c0949ee47ee2d3a332578633acb4af0c0216bc Added the pastes. diff -r 49c0949ee47e -r 42de15334db1 app/assets/javascripts/pastes.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/assets/javascripts/pastes.js Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff -r 49c0949ee47e -r 42de15334db1 app/assets/stylesheets/pastes.css.scss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/assets/stylesheets/pastes.css.scss Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,3 @@ +// Place all the styles related to the pastes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff -r 49c0949ee47e -r 42de15334db1 app/assets/stylesheets/scaffolds.css.scss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/assets/stylesheets/scaffolds.css.scss Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff -r 49c0949ee47e -r 42de15334db1 app/controllers/pastes_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controllers/pastes_controller.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,85 @@ +class PastesController < ApplicationController + # GET /pastes + # GET /pastes.json + def index + @pastes = Paste.all + + respond_to do |format| + format.html # index.html.erb + format.json { render :json => @pastes } + end + end + + # GET /pastes/1 + # GET /pastes/1.json + def show + @paste = Paste.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render :json => @paste } + end + end + + # GET /pastes/new + # GET /pastes/new.json + def new + @paste = Paste.new + + respond_to do |format| + format.html # new.html.erb + format.json { render :json => @paste } + end + end + + # GET /pastes/1/edit + def edit + @paste = Paste.find(params[:id]) + end + + # POST /pastes + # POST /pastes.json + def create + @paste = Paste.new + @paste.paste = params[:paste][:paste] + @paste.ip = request.remote_ip + + respond_to do |format| + if @paste.save + format.html { redirect_to @paste, :notice => 'Paste was successfully created.' } + format.json { render :json => @paste, :status => :created, :location => @paste } + else + format.html { render :action => "new" } + format.json { render :json => @paste.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /pastes/1 + # PUT /pastes/1.json + def update + @paste = Paste.find(params[:id]) + + respond_to do |format| + if @paste.update_attributes(params[:paste]) + format.html { redirect_to @paste, :notice => 'Paste was successfully updated.' } + format.json { head :no_content } + else + format.html { render :action => "edit" } + format.json { render :json => @paste.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /pastes/1 + # DELETE /pastes/1.json + def destroy + @paste = Paste.find(params[:id]) + @paste.destroy + + respond_to do |format| + format.html { redirect_to pastes_url } + format.json { head :no_content } + end + end +end diff -r 49c0949ee47e -r 42de15334db1 app/helpers/pastes_helper.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/helpers/pastes_helper.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,2 @@ +module PastesHelper +end diff -r 49c0949ee47e -r 42de15334db1 app/models/paste.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/models/paste.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,10 @@ +class Paste < ActiveRecord::Base + attr_accessible :paste + before_validation :set_paste_hash + validates :paste, :paste_hash, :ip, :presence => true + validates :paste, :length => { :maximum => 1_000_000 } + + def set_paste_hash + self.paste_hash = Digest::SHA512.hexdigest(paste) + end +end diff -r 49c0949ee47e -r 42de15334db1 app/views/pastes/_form.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/pastes/_form.html.erb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,21 @@ +<%= form_for(@paste) do |f| %> + <% if @paste.errors.any? %> +
+

<%= pluralize(@paste.errors.count, "error") %> prohibited this paste from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :paste %>
+ <%= f.text_area :paste %> +
+
+ <%= f.submit %> +
+<% end %> diff -r 49c0949ee47e -r 42de15334db1 app/views/pastes/edit.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/pastes/edit.html.erb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,6 @@ +

Editing paste

+ +<%= render 'form' %> + +<%= link_to 'Show', @paste %> | +<%= link_to 'Back', pastes_path %> diff -r 49c0949ee47e -r 42de15334db1 app/views/pastes/index.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/pastes/index.html.erb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,23 @@ +

Listing pastes

+ + + + + + + + + +<% @pastes.each do |paste| %> + + + + + + +<% end %> +
IdPaste
<%= link_to paste.id, paste %><%= paste.paste %><%= link_to 'Edit', edit_paste_path(paste) %><%= link_to 'Destroy', paste, :method => :delete, :data => { :confirm => 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Paste', new_paste_path %> diff -r 49c0949ee47e -r 42de15334db1 app/views/pastes/new.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/pastes/new.html.erb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,5 @@ +

New paste

+ +<%= render 'form' %> + +<%= link_to 'Back', pastes_path %> diff -r 49c0949ee47e -r 42de15334db1 app/views/pastes/show.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/pastes/show.html.erb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Paste: + <%= @paste.paste %> +

+ +

+ Hash: + <%= @paste.paste_hash %> +

+ + +<%= link_to 'Edit', edit_paste_path(@paste) %> | +<%= link_to 'Back', pastes_path %> diff -r 49c0949ee47e -r 42de15334db1 config/routes.rb --- a/config/routes.rb Sun Aug 26 11:03:59 2012 -0700 +++ b/config/routes.rb Sun Aug 26 11:28:23 2012 -0700 @@ -1,4 +1,6 @@ Zeropaste::Application.routes.draw do + resources :pastes + # The priority is based upon order of creation: # first created -> highest priority. diff -r 49c0949ee47e -r 42de15334db1 db/migrate/20120826180414_create_pastes.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/db/migrate/20120826180414_create_pastes.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,12 @@ +class CreatePastes < ActiveRecord::Migration + def change + create_table :pastes do |t| + t.string :ip, :null => false + t.text :paste, :null => false + t.string :hash, :null => false + + t.timestamps + end + add_index :pastes, [:ip, :hash], :unique => true + end +end diff -r 49c0949ee47e -r 42de15334db1 db/migrate/20120826182012_change_column_name_to_conform_ar.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/db/migrate/20120826182012_change_column_name_to_conform_ar.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,5 @@ +class ChangeColumnNameToConformAr < ActiveRecord::Migration + def change + rename_column :pastes, :hash, :paste_hash + end +end diff -r 49c0949ee47e -r 42de15334db1 db/schema.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/db/schema.rb Sun Aug 26 11:28:23 2012 -0700 @@ -0,0 +1,25 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20120826182012) do + + create_table "pastes", :force => true do |t| + t.string "ip", :null => false + t.text "paste", :null => false + t.string "paste_hash", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "pastes", ["ip", "paste_hash"], :name => "index_pastes_on_ip_and_hash", :unique => true + +end