Skip to content

Instantly share code, notes, and snippets.

# 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>
@rbarazi
rbarazi / application.html.erb
Created April 11, 2010 15:48
[Beginning Rails 3] Listing 12-13. Update to app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag 'jquery-1.4.2.min', 'rails', 'application' %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="header">
@rbarazi
rbarazi / _search.html.erb
Created April 11, 2010 15:47
[Beginning Rails 3] Listing 12-12. The app/views/articles/_search.html.erb File
<%= form_tag search_articles_path, :method => :get do %>
<p>
Search
<%= text_field_tag :keyword, params[:keyword] %>
</p>
<% end %>