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
29 changed files
with
448 additions
and
29 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
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 GrampostsController < ApplicationController | ||
before_filter :signed_in_user, only: [:create, :destroy] | ||
before_filter :correct_user, only: :destroy | ||
|
||
def create | ||
@grampost = current_user.gramposts.build(params[:grampost]) | ||
if @grampost.save | ||
flash[:success] = "Grampost created!" | ||
redirect_to root_path | ||
else | ||
@feed_items = [] | ||
render 'static_pages/home' | ||
end | ||
end | ||
|
||
def destroy | ||
@grampost.destroy | ||
redirect_back_or root_path | ||
end | ||
|
||
def index | ||
end | ||
|
||
private | ||
def correct_user | ||
@grampost = current_user.gramposts.find_by_id(params[:id]) | ||
redirect_to root_path if @grampost.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,15 @@ | ||
module GrampostsHelper | ||
|
||
def wrap(description) | ||
sanitize(raw(description.split.map{ |s| wrap_long_string(s) }.join(' '))) | ||
end | ||
|
||
private | ||
|
||
def wrap_long_string(text, max_width = 30) | ||
zero_width_space = "​" | ||
regex = /.{1,#{max_width}}/ | ||
(text.length < max_width) ? text : | ||
text.scan(regex).join(zero_width_space) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# == Schema Information | ||
# | ||
# Table name: gramposts | ||
# | ||
# id :integer not null, primary key | ||
# title :string(255) | ||
# description :string(255) | ||
# user_id :integer | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class Grampost < ActiveRecord::Base | ||
attr_accessible :title, :description | ||
belongs_to :user | ||
|
||
validates :user_id, presence: true | ||
validates :title, presence: true, length: { maximum: 140 } | ||
|
||
default_scope order: 'gramposts.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="title"><%= grampost.title %></span> | ||
<span class="content"><%= wrap(grampost.description) %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(grampost.created_at) %> ago. | ||
</span> | ||
<% if current_user?(grampost.user) %> | ||
<%= link_to "delete", grampost, method: :delete, | ||
confirm: "You sure?", | ||
title: grampost.title %> | ||
<% 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
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="gramposts"> | ||
<%= 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,16 @@ | ||
<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="title"><%= feed_item.title %></span> | ||
<span class="content"><%= wrap(feed_item.description) %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(feed_item.created_at) %> ago. | ||
</span> | ||
<% if current_user?(feed_item.user) %> | ||
<%= link_to "delete", feed_item, method: :delete, | ||
confirm: "You sure?", | ||
title: feed_item.title %> | ||
<% 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,8 @@ | ||
<%= form_for(@grampost) do |f| %> | ||
<%= render 'shared/error_messages', object: f.object %> | ||
<div class="field"> | ||
<%= f.text_field :title, placeholder: "Grampost title..." %> | ||
<%= f.text_area :description, placeholder: "Describe the details of your grampost..." %> | ||
</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,9 @@ | ||
<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> |
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,13 +1,30 @@ | ||
<div class="center hero-unit"> | ||
<h1>Welcome to Gramlist</h1> | ||
<% if signed_in? %> | ||
<div class="row"> | ||
<aside class="span4"> | ||
<section> | ||
<%= render 'shared/user_info' %> | ||
</section> | ||
<section> | ||
<%= render 'shared/grampost_form' %> | ||
</section> | ||
</aside> | ||
<div class="span8"> | ||
<h3>Grampost Feed</h3> | ||
<%= render 'shared/feed' %> | ||
</div> | ||
</div> | ||
<% else %> | ||
<div class="center hero-unit"> | ||
<h1>Welcome to Gramlist</h1> | ||
|
||
<h2> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</h2> | ||
|
||
<%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %> | ||
</div> | ||
<h2> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</h2> | ||
<%= 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,12 @@ | ||
class CreateGramposts < ActiveRecord::Migration | ||
def change | ||
create_table :gramposts do |t| | ||
t.string :title | ||
t.string :description | ||
t.integer :user_id | ||
|
||
t.timestamps | ||
end | ||
add_index :gramposts, [: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,10 @@ | |
admin true | ||
end | ||
end | ||
|
||
factory :grampost do | ||
title "Post Title" | ||
description "Lorem Ipsum" | ||
user | ||
end | ||
end |
Oops, something went wrong.