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
34 changed files
with
406 additions
and
28 deletions.
There are no files selected for viewing
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,3 @@ | ||
# 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/ |
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,3 @@ | ||
// Place all the styles related to the microposts controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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 :signed_in_user, :only => [:create, :destroy] | ||
before_filter :correct_user, :only => :destroy | ||
|
||
def index | ||
end | ||
|
||
def create | ||
@micropost = current_user.microposts.build(params[:micropost]) | ||
if @micropost.save | ||
flash[:success] = "Micropost created!" | ||
redirect_to root_path | ||
else | ||
@feed_items = current_user.feed.paginate(:page => params[:page]) | ||
render 'static_pages/home' | ||
end | ||
end | ||
|
||
def destroy | ||
@micropost.destroy | ||
redirect_to root_path | ||
end | ||
|
||
private | ||
def correct_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module MicropostsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module UsersHelper | ||
def gravatar_for(user) | ||
def gravatar_for(user, options = { :size => 50 }) | ||
gravatar_id = Digest::MD5::hexdigest(user.email.downcase) | ||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}" | ||
image_tag(gravatar_url, :alt => user.name, :class => "gravatar") | ||
size = options[:size] | ||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" | ||
image_tag(gravatar_url, :alt => user.name, :class => "gravatar") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# == Schema Information | ||
# | ||
# Table name: microposts | ||
# | ||
# id :integer not null, primary key | ||
# content :string(255) | ||
# user_id :integer | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class Micropost < ActiveRecord::Base | ||
attr_accessible :content | ||
belongs_to :user | ||
|
||
validates :user_id, | ||
:presence => true | ||
validates :content, | ||
:presence => true, | ||
:length => { :maximum => 140 } | ||
|
||
default_scope :order => '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
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,12 @@ | ||
<li> | ||
<span class="content"><%= micropost.content %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(micropost.created_at) %> | ||
</span> | ||
<% if current_user?(micropost.user) %> | ||
<%= link_to 'delete', micropost, :method => :delete, | ||
:data => { :confirm => 'You sure?' }, | ||
:title => micropost.content | ||
%> | ||
<% end %> | ||
</li> |
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,2 @@ | ||
<h1>Microposts#create</h1> | ||
<p>Find me in app/views/microposts/create.html.erb</p> |
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,2 @@ | ||
<h1>Microposts#destroy</h1> | ||
<p>Find me in app/views/microposts/destroy.html.erb</p> |
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,6 @@ | ||
<% if @feed_items.any? %> | ||
<ol class="microposts"> | ||
<%= render :partial => 'shared/feed_item', :collection => @feed_items %> | ||
</ol> | ||
<%= 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,13 @@ | ||
<li id="<%= feed_item.id %>"> | ||
<%= link_to gravatar_for(feed_item.user), feed_item.user %> | ||
<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) %> | ||
</span> | ||
<% if current_user?(feed_item.user) %> | ||
<%= link_to 'delete', feed_item, :method => :delete, :data => { :confirm => "You sure?" } %> | ||
<% end %> | ||
</li> |
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,7 @@ | ||
<%= form_for(@micropost) do |f| %> | ||
<%= render 'shared/error_messages', :object => f.object %> | ||
<div class="field"> | ||
<%= f.text_area :content, :rows => 5, :placeholder => "Compose new micropost..." %> | ||
</div> | ||
<%= f.submit 'Post', :class => 'btn btn-large btn-primary' %> | ||
<% 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,10 @@ | ||
<a href="<%= user_path(current_user) %>"> | ||
<%= gravatar_for current_user, :size => 52 %> | ||
</a> | ||
<h1><%= current_user.name %></h1> | ||
<span> | ||
<%= link_to 'view my profile', current_user %> | ||
</span> | ||
<span> | ||
<%= pluralize(current_user.microposts.count, 'micropost') %> | ||
</span> |
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,11 +1,28 @@ | ||
<div class="center hero-unit"> | ||
<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_path, :class => 'btn btn-large btn-primary' %> | ||
</div> | ||
<% if signed_in? %> | ||
<div class="row"> | ||
<div class="span4"> | ||
<section> | ||
<%= render :partial => 'shared/user_info' %> | ||
</section> | ||
<section> | ||
<%= render :partial => 'shared/micropost_form' %> | ||
</section> | ||
</div> | ||
<div class="span8"> | ||
<h3>Micropost Feed</h3> | ||
<%= render 'shared/feed' %> | ||
</div> | ||
</div> | ||
<% else %> | ||
<div class="center hero-unit"> | ||
<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_path, :class => 'btn btn-large btn-primary' %> | ||
</div> | ||
|
||
<%= link_to image_tag('rails.png', :alt => 'Rails'), 'http://rubyonrails.org' %> | ||
<%= link_to image_tag('rails.png', :alt => 'Rails'), 'http://rubyonrails.org' %> | ||
<% 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
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 @@ | ||
class CreateMicroposts < ActiveRecord::Migration | ||
def change | ||
create_table :microposts do |t| | ||
t.string :content | ||
t.integer :user_id | ||
|
||
t.timestamps | ||
end | ||
add_index :microposts, [:user_id, :created_at] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,9 @@ | |
admin true | ||
end | ||
end | ||
|
||
factory :micropost do | ||
content "Lorem ipsum" | ||
user | ||
end | ||
end |
Oops, something went wrong.