Skip to content

Commit

Permalink
Done with the demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
zarniwoop committed May 5, 2011
1 parent dd41c4b commit 7cc33b6
Show file tree
Hide file tree
Showing 32 changed files with 675 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.bundle
db/*.sqlite3
log/*.log
*.log
tmp/**/*
tmp/*
doc/api
doc/app
*.swp
*~
.DS_Store
73 changes: 73 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (= 3.0.7)
mail (~> 2.2.15)
actionpack (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activeresource (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
arel (2.0.9)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.7)
actionmailer (= 3.0.7)
actionpack (= 3.0.7)
activerecord (= 3.0.7)
activeresource (= 3.0.7)
activesupport (= 3.0.7)
bundler (~> 1.0)
railties (= 3.0.7)
railties (3.0.7)
actionpack (= 3.0.7)
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
sqlite3-ruby (1.3.2)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)

PLATFORMS
ruby

DEPENDENCIES
rails (= 3.0.7)
sqlite3-ruby (= 1.3.2)
83 changes: 83 additions & 0 deletions app/controllers/microposts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class MicropostsController < ApplicationController
# GET /microposts
# GET /microposts.xml
def index
@microposts = Micropost.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @microposts }
end
end

# GET /microposts/1
# GET /microposts/1.xml
def show
@micropost = Micropost.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @micropost }
end
end

# GET /microposts/new
# GET /microposts/new.xml
def new
@micropost = Micropost.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @micropost }
end
end

# GET /microposts/1/edit
def edit
@micropost = Micropost.find(params[:id])
end

# POST /microposts
# POST /microposts.xml
def create
@micropost = Micropost.new(params[:micropost])

respond_to do |format|
if @micropost.save
format.html { redirect_to(@micropost, :notice => 'Micropost was successfully created.') }
format.xml { render :xml => @micropost, :status => :created, :location => @micropost }
else
format.html { render :action => "new" }
format.xml { render :xml => @micropost.errors, :status => :unprocessable_entity }
end
end
end

# PUT /microposts/1
# PUT /microposts/1.xml
def update
@micropost = Micropost.find(params[:id])

respond_to do |format|
if @micropost.update_attributes(params[:micropost])
format.html { redirect_to(@micropost, :notice => 'Micropost was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @micropost.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /microposts/1
# DELETE /microposts/1.xml
def destroy
@micropost = Micropost.find(params[:id])
@micropost.destroy

respond_to do |format|
format.html { redirect_to(microposts_url) }
format.xml { head :ok }
end
end
end
83 changes: 83 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@users = User.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end

# GET /users/1
# GET /users/1.xml
def show
@user = User.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end

# GET /users/new
# GET /users/new.xml
def new
@user = User.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user }
end
end

# GET /users/1/edit
def edit
@user = User.find(params[:id])
end

# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])

respond_to do |format|
if @user.save
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end

# PUT /users/1
# PUT /users/1.xml
def update
@user = User.find(params[:id])

respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /users/1
# DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy

respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/microposts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MicropostsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
5 changes: 5 additions & 0 deletions app/models/micropost.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Micropost < ActiveRecord::Base
belongs_to :user

validates :content, :length => { :maximum => 140 }
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ActiveRecord::Base
has_many :microposts
end
25 changes: 25 additions & 0 deletions app/views/microposts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_for(@micropost) do |f| %>
<% if @micropost.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2>

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

<div class="field">
<%= f.label :content %><br />
<%= f.text_field :content %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.text_field :user_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/microposts/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing micropost</h1>

<%= render 'form' %>

<%= link_to 'Show', @micropost %> |
<%= link_to 'Back', microposts_path %>
25 changes: 25 additions & 0 deletions app/views/microposts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1>Listing microposts</h1>

<table>
<tr>
<th>Content</th>
<th>User</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @microposts.each do |micropost| %>
<tr>
<td><%= micropost.content %></td>
<td><%= micropost.user_id %></td>
<td><%= link_to 'Show', micropost %></td>
<td><%= link_to 'Edit', edit_micropost_path(micropost) %></td>
<td><%= link_to 'Destroy', micropost, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Micropost', new_micropost_path %>
5 changes: 5 additions & 0 deletions app/views/microposts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New micropost</h1>

<%= render 'form' %>

<%= link_to 'Back', microposts_path %>
15 changes: 15 additions & 0 deletions app/views/microposts/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>

<p>
<b>Content:</b>
<%= @micropost.content %>
</p>

<p>
<b>User:</b>
<%= @micropost.user_id %>
</p>


<%= link_to 'Edit', edit_micropost_path(@micropost) %> |
<%= link_to 'Back', microposts_path %>
25 changes: 25 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

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

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing user</h1>

<%= render 'form' %>

<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
Loading

0 comments on commit 7cc33b6

Please sign in to comment.