-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
505 additions
and
38 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class MicropostsController < ApplicationController | ||
|
||
before_filter :authenticate, :only => [:create, :destroy] | ||
before_filter :authorized_user, :only => :destroy | ||
|
||
def create | ||
@micropost = current_user.microposts.build(params[:micropost]) | ||
if @micropost.save | ||
flash[:success] = "Micropost created!" | ||
redirect_to root_path | ||
else | ||
@feed_items = [] | ||
render 'pages/home' | ||
end | ||
end | ||
|
||
def destroy | ||
@micropost.destroy | ||
redirect_back_or root_path | ||
end | ||
|
||
private | ||
|
||
def authorized_user | ||
@micropost = current_user.microposts.find_by_id(params[:id]) | ||
redirect_to root_path if @micropost.nil? | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Micropost < ActiveRecord::Base | ||
attr_accessible :content | ||
|
||
belongs_to :user | ||
|
||
validates :content, :presence => true, :length => { :maximum => 140 } | ||
validates :user_id, :presence => true | ||
|
||
default_scope :order => 'microposts.created_at DESC' | ||
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<tr> | ||
<td class="micropost"> | ||
<span class="content"><%= micropost.content %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(micropost.created_at) %> ago. | ||
</span> | ||
</td> | ||
<% user = micropost.user rescue User.find(micropost.user_id) %> | ||
<% if current_user?(user) %> | ||
<td> | ||
<%= link_to "delete", micropost, :method => :delete, | ||
:confirm => "You sure?", | ||
:title => micropost.content %> | ||
</td> | ||
<% end %> | ||
</tr> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
<h1>Sample App</h1> | ||
<p> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</p> | ||
|
||
<%= link_to "Sign up now!", 'signup', :class => "signup_button round" %> | ||
<% if signed_in? %> | ||
<table class="front" summary="For signed-in users"> | ||
<tr> | ||
<td class="main"> | ||
<h1 class="micropost">What's up?</h1> | ||
<%= render 'shared/micropost_form' %> | ||
<%= render 'shared/feed' %> | ||
</td> | ||
<td class="sidebar round"> | ||
<%= render 'shared/user_info' %> | ||
</td> | ||
</tr> | ||
</table> | ||
<% else %> | ||
|
||
<h1>Sample App</h1> | ||
<p> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</p> | ||
|
||
<%= link_to "Sign up now!", 'signup', :class => "signup_button round" %> | ||
|
||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% unless @feed_items.empty? %> | ||
<table class="microposts" summary="User microposts"> | ||
<%= render :partial => 'shared/feed_item', :collection => @feed_items %> | ||
</table> | ||
<%= will_paginate @feed_items %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<tr> | ||
<td class="gravatar"> | ||
<%= link_to gravatar_for(feed_item.user), feed_item.user %> | ||
</td> | ||
<td class="micropost"> | ||
<span class="user"> | ||
<%= link_to feed_item.user.name, feed_item.user %> | ||
</span> | ||
<span class="content"><%= feed_item.content %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(feed_item.created_at) %> ago. | ||
</span> | ||
</td> | ||
<% if current_user?(feed_item.user) %> | ||
<td> | ||
<%= link_to "delete", feed_item, :method => :delete, | ||
:confirm => "You sure?", | ||
:title => feed_item.content %> | ||
</td> | ||
<% end %> | ||
</tr> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= form_for @micropost do |f| %> | ||
<%= render 'shared/error_messages', :object => f.object %> | ||
<div class="field"> | ||
<%= f.text_area :content %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit "Submit" %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="user_info"> | ||
<a href="<%= user_path(current_user) %>"> | ||
<%= gravatar_for current_user, :size => 30 %> | ||
<span class="user_name"> | ||
<%= current_user.name %> | ||
</span> | ||
<span class="microposts"> | ||
<%= pluralize(current_user.microposts.count, "micropost") %> | ||
</span> | ||
</a> | ||
</div> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateMicroposts < ActiveRecord::Migration | ||
def self.up | ||
create_table :microposts do |t| | ||
t.string :content | ||
t.integer :user_id | ||
|
||
t.timestamps | ||
end | ||
add_index :microposts, :user_id | ||
add_index :microposts, :created_at | ||
end | ||
|
||
def self.down | ||
drop_table :microposts | ||
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
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
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
Binary file not shown.
Oops, something went wrong.