Skip to content

Instantly share code, notes, and snippets.

@rbarazi
rbarazi / with_dot_notation.rb
Created June 10, 2010 16:43
Hash with dot notations
class HashWithDotNotation < Hash
def initialize(constructor = {})
if constructor.is_a?(Hash)
super()
self.replace(constructor)
else
super(constructor)
end
end
/* RESET STYLES FROM BLUEPRINT */
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0;padding:0;border:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}
body {line-height:1.5;}
table {border-collapse:separate;border-spacing:0;}
caption, th, td {text-align:left;font-weight:normal;}
table, td, th {vertical-align:middle;}
blockquote:before, blockquote:after, q:before, q:after {content:"";}
blockquote, q {quotes:"" "";}
a img {border:none;}
# bundle_path "vendor/bundler_gems" #Will be vendor/gems in RAILS 3
#disable_system_gems
source :gemcutter
gem "rails", "2.3.5"
gem 'mysql'
gem "compass", "0.8.17"
gem "haml", "2.2.10"
gem "will_paginate", "2.3.11"
gem "aws-s3", "0.6.2", :require => "aws/s3"
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Blog
class Application < Rails::Application
@rbarazi
rbarazi / pt-br.yml
Created May 5, 2010 21:50
[Beginning Rails 3] Listing 11-9. Brazilian Portuguese Locale File in config/locales/pt-br.yml
pt-br:
general:
are_you_sure: Tem certeza?
back: Volta
cancel: Cancelar
create: Criar
delete: Apagar
edit: Editar
editing: Editando
footer: Um blog simples desenvolvido para o livro
@rbarazi
rbarazi / notifier.rb
Created May 5, 2010 15:43
[Beginning Rails 3] Listing 9-7. Updated Notifier Mailer in app/mailers/notifier.rb
class Notifier < ActionMailer::Base
default :from => "from@example.com"
def email_friend(article, sender_name, receiver_email)
@article = article
@sender_name = sender_name
mail :to => receiver_email, :subject => "Interesting Article"
end
end
@rbarazi
rbarazi / _comment.html.erb
Created May 3, 2010 21:13
[Beginning Rails 3] Listing 7-30. Edit Controls for Comment in app/views/comments/_comment.html.erb
<%= div_for comment do %>
<h3>
<%= comment.name %> &lt;<%= comment.email %>&gt; said:
<% if @article.owned_by? current_user %>
<span class='actions'>
<%= link_to 'Delete', [@article, comment], :confirm => 'Are you sure?', :method => :delete %>
</span>
<% end %>
</h3>
<%= comment.body %>
@rbarazi
rbarazi / comments_controller.rb
Created May 3, 2010 21:09
[Beginning Rails 3] Listing 7-26. Authorization Before Deleting a Comment in app/controllers/comments_controller.rb
class CommentsController < ApplicationController
before_filter :load_article, :except => :destroy
before_filter :authenticate, :only => :destroy
def create
@comment = @article.comments.new(params[:comment])
if @comment.save
redirect_to @article, :notice => 'Thanks for your comment'
else
redirect_to @article, :alert => 'Unable to add comment'
@rbarazi
rbarazi / article.rb
Created May 3, 2010 20:13
[Beginning Rails 3] Listing 7-28. Updated app/models/article.rb
class Article < ActiveRecord::Base
validates :title, :presence => true
validates :body, :presence => true
belongs_to :user
has_and_belongs_to_many :categories
has_many :comments
scope :published, where("articles.published_at IS NOT NULL")
scope :draft, where("articles.published_at IS NULL")
@rbarazi
rbarazi / application.html.erb
Created May 3, 2010 18:53
[Beginning Rails 3] Listing 7-10. Updated Application Layout Template in app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>