This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ..", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentObserver < ActiveRecord::Observer | |
def after_create(comment) | |
Notifier.comment_added(comment).deliver | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert("<%= @comment.errors.full_messages.to_sentence %>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#<%= dom_id(@comment) %>").remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= div_for comment do %> | |
<h3> | |
<%= comment.name %> <<%= comment.email %>> 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 %> |
NewerOlder