Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
adding revised episode 147
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Oct 13, 2011
1 parent a958167 commit 2ba0ecd
Show file tree
Hide file tree
Showing 130 changed files with 1,885 additions and 0 deletions.
8 changes: 8 additions & 0 deletions episode-147/revised/README
@@ -0,0 +1,8 @@
Railscasts Episode #147: Sortable Lists (revised)

http://railscasts.com/episodes/147-sortable-lists-revised

Commands

rails g migration add_position_to_faqs position:integer
rake db:migrate
5 changes: 5 additions & 0 deletions episode-147/revised/faqapp-after/.gitignore
@@ -0,0 +1,5 @@
.bundle
db/*.sqlite3
log/*.log
tmp/
.sass-cache/
16 changes: 16 additions & 0 deletions episode-147/revised/faqapp-after/Gemfile
@@ -0,0 +1,16 @@
source 'http://rubygems.org'

gem 'rails', '3.1.1'
gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

gem 'acts_as_list'
117 changes: 117 additions & 0 deletions episode-147/revised/faqapp-after/Gemfile.lock
@@ -0,0 +1,117 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.1)
actionpack (= 3.1.1)
mail (~> 2.3.0)
actionpack (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.2)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.2)
activemodel (3.1.1)
activesupport (= 3.1.1)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
activesupport (3.1.1)
multi_json (~> 1.0)
acts_as_list (0.1.4)
arel (2.2.1)
builder (3.0.0)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.1.2)
erubis (2.7.0)
execjs (1.2.9)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.16)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
polyglot (0.3.2)
rack (1.3.3)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.1)
actionmailer (= 3.1.1)
actionpack (= 3.1.1)
activerecord (= 3.1.1)
activeresource (= 3.1.1)
activesupport (= 3.1.1)
bundler (~> 1.0)
railties (= 3.1.1)
railties (3.1.1)
actionpack (= 3.1.1)
activesupport (= 3.1.1)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.10)
json (~> 1.4)
sass (3.1.10)
sass-rails (3.1.4)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
sprockets (~> 2.0.0)
tilt (~> 1.3.2)
sprockets (2.0.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.30)
uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)

PLATFORMS
ruby

DEPENDENCIES
acts_as_list
coffee-rails (~> 3.1.1)
jquery-rails
rails (= 3.1.1)
sass-rails (~> 3.1.4)
sqlite3
uglifier (>= 1.0.3)
7 changes: 7 additions & 0 deletions episode-147/revised/faqapp-after/README
@@ -0,0 +1,7 @@
= RailsCasts Example Application

Run these commands to try it out.

bundle
rake db:setup
rails s
7 changes: 7 additions & 0 deletions episode-147/revised/faqapp-after/Rakefile
@@ -0,0 +1,7 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Faqapp::Application.load_tasks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,10 @@
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .
@@ -0,0 +1,9 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
jQuery ->
$('#faqs').sortable
axis: 'y'
handle: '.handle'
update: ->
$.post($(this).data('update-url'), $(this).sortable('serialize'))
@@ -0,0 +1,104 @@
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/

html, body {
background-color: #4B7399;
font-family: Verdana, Helvetica, Arial;
font-size: 14px;
}

a img {
border: none;
}

a {
color: #0000FF;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

.clear {
clear: both;
height: 0;
overflow: hidden;
}

#container {
width: 75%;
margin: 0 auto;
background-color: #FFF;
padding: 20px 40px;
border: solid 1px black;
margin-top: 20px;
}

#flash_notice, #flash_error, #flash_alert {
padding: 5px 8px;
margin: 10px 0;
}

#flash_notice {
background-color: #CFC;
border: solid 1px #6C6;
}

#flash_error, #flash_alert {
background-color: #FCC;
border: solid 1px #C66;
}

form label {
display: block;
margin-bottom: 2px;
}

form .field, form .actions {
margin: 12px 0;
}

.fieldWithErrors {
display: inline;
}

.error_messages {
width: 400px;
border: 2px solid #CF0000;
padding: 0px;
margin-bottom: 20px;
background-color: #f0f0f0;
font-size: 12px;
}

.error_messages h2 {
text-align: left;
font-weight: bold;
padding: 5px 10px;
font-size: 12px;
margin: 0;
background-color: #c00;
color: #fff;
}

.error_messages p {
margin: 8px 10px;
}

.error_messages ul {
margin: 15px 0;
}

ul {
padding-left: 20px;
}

ul li {
margin: 5px 0;
}
@@ -0,0 +1,8 @@
// Place all the styles related to the faqs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#faqs .handle {
font-size: 12px;
color: #777;
cursor: move;
}
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end
@@ -0,0 +1,48 @@
class FaqsController < ApplicationController
def index
@faqs = Faq.order("position")
end

def show
@faq = Faq.find(params[:id])
end

def new
@faq = Faq.new
end

def create
@faq = Faq.new(params[:faq])
if @faq.save
redirect_to @faq, notice: "Successfully created FAQ."
else
render :new
end
end

def edit
@faq = Faq.find(params[:id])
end

def update
@faq = Faq.find(params[:id])
if @faq.update_attributes(params[:faq])
redirect_to @faq, notice: "Successfully updated FAQ."
else
render :edit
end
end

def destroy
@faq = Faq.find(params[:id])
@faq.destroy
redirect_to faqs_url, notice: "Successfully destroyed FAQ."
end

def sort
params[:faq].each_with_index do |id, index|
Faq.update_all({position: index+1}, {id: id})
end
render nothing: true
end
end
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions episode-147/revised/faqapp-after/app/helpers/faqs_helper.rb
@@ -0,0 +1,2 @@
module FaqsHelper
end
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions episode-147/revised/faqapp-after/app/models/faq.rb
@@ -0,0 +1,3 @@
class Faq < ActiveRecord::Base
acts_as_list
end
25 changes: 25 additions & 0 deletions episode-147/revised/faqapp-after/app/views/faqs/_form.html.erb
@@ -0,0 +1,25 @@
<%= form_for(@faq) do |f| %>
<% if @faq.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@faq.errors.count, "error") %> prohibited this faq from being saved:</h2>

<ul>
<% @faq.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :question %><br />
<%= f.text_area :question %>
</div>
<div class="field">
<%= f.label :answer %><br />
<%= f.text_area :answer %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions episode-147/revised/faqapp-after/app/views/faqs/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing faq</h1>

<%= render 'form' %>
<%= link_to 'Show', @faq %> |
<%= link_to 'Back', faqs_path %>

0 comments on commit 2ba0ecd

Please sign in to comment.