Skip to content

Instantly share code, notes, and snippets.

// postgres = "0.11.5"
extern crate postgres;
use postgres::{Connection, SslMode};
fn main() {
let conn = Connection::connect("postgres://foo:bar@localhost/playground", SslMode::None)
.unwrap();
setup_db(&conn);
ccarneiroj@ccj-air:~/code/pizzaria [git:master]
→ bundle install
Updating git://github.com/merbjedi/active_merchant.git
Updating git://github.com/mislav/will_paginate.git
Updating git://github.com/thoughtbot/paperclip.git
Updating git://github.com/rails/rails.git
Checking out files: 100% (1890/1890), done.
Fetching source index from http://rubygems.org/
Updating git://github.com/rails/rails.git
Updating git://github.com/thoughtbot/paperclip.git
@ccjr
ccjr / seeds.rb
Created May 2, 2010 19:26
[Beginning Rails 3] Listing 5-38. Current Seeds File in db/seeds.rb
user = User.create :email => 'mary@example.com',
:password => 'guessit',
:password_confirmation => 'guessit'
Category.create [{:name => 'Programming'},
{:name => 'Event'},
{:name => 'Travel'},
{:name => 'Music'},
{:name => 'TV'}]
user.articles.create :title => 'Advanced Active Record',
:body => "Models need to relate to each other. In the real world, ..",
@ccjr
ccjr / comment_observer.rb
Created April 6, 2010 20:03
[Beginning Rails 3] Listing 9-13. Updates to app/model/comment_observer.rb
class CommentObserver < ActiveRecord::Observer
def after_create(comment)
Notifier.comment_added(comment).deliver
end
end
@ccjr
ccjr / comment_added.html.erb
Created April 6, 2010 20:02
[Beginning Rails 3] Listing 9-12. The comment_added mailer template in app/views/notifier/comment_added.html.erb
<html>
<body>
<p>
Someone added a comment to one of your articles <i><%= @article.title %></i>.
Go read the comment: <%= link_to @article.title, article_url(@article, :host => 'localhost:3000') %>.
</p>
</body>
</html>
@ccjr
ccjr / notifier.rb
Created April 6, 2010 19:51
[Beginning Rails 3] Listing 9-11. Adding the comment_added method to app/models/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
attachments["rails.png"] = File.read(Rails.root.join("public/images/rails.png"))
mail :to => receiver_email, :subject => "Interesting Article"
end
@ccjr
ccjr / fail_create.js.erb
Created April 3, 2010 21:36
[Beginning Rails 3] Listing 8-9. The template in app/views/comments/fail_create.js.erb
alert("<%= @comment.errors.full_messages.to_sentence %>");
@ccjr
ccjr / destroy.js.erb
Created April 3, 2010 19:58
[Beginning Rails 3] Listing 8-12. The app/views/comment/destroy.js.erb file
$("#<%= dom_id(@comment) %>").remove()
@ccjr
ccjr / comments_controller.rb
Created April 3, 2010 19:57
[Beginning Rails 3] Listing 8-11. The comments controllert 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
respond_to do |format|
format.html { redirect_to @article, :notice => 'Thanks for your comment' }
format.js
@ccjr
ccjr / _comment.html.erb
Created April 3, 2010 19:55
[Beginning Rails 3] Listing 8-10. The template 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, :remote => true %>
</span>
<% end %>
</h3>
<%= comment.body %>