Skip to content

Commit

Permalink
Added tagging and avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
Diope committed Aug 14, 2015
1 parent e17e821 commit f1329e3
Show file tree
Hide file tree
Showing 29 changed files with 185 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,9 @@
/log/*
!/log/.keep
/tmp

#MAC_OSX
.DS_Store

#Avatars
/public/system
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -14,7 +14,7 @@ gem 'bourbon'
gem 'neat'
gem 'devise'
gem 'refills'
gem 'carrierwave', '~> 0.10.0'
gem "paperclip", "~> 4.3"
gem 'thin', '~> 1.6.3'
gem 'font-awesome-rails', '~> 4.3.0.0'
gem 'will_paginate', '~> 3.0.7'
Expand Down
18 changes: 12 additions & 6 deletions Gemfile.lock
Expand Up @@ -46,11 +46,10 @@ GEM
builder (3.2.2)
byebug (5.0.0)
columnize (= 0.9.0)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.7)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -93,6 +92,7 @@ GEM
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.6.1)
mimemagic (0.3.0)
mini_portile (0.6.2)
minitest (5.7.0)
multi_json (1.11.2)
Expand All @@ -102,6 +102,12 @@ GEM
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
paperclip (4.3.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
pg (0.18.2)
pry (0.10.1)
coderay (~> 1.1.0)
Expand Down Expand Up @@ -188,14 +194,14 @@ PLATFORMS
DEPENDENCIES
bourbon
byebug
carrierwave (~> 0.10.0)
coffee-rails (~> 4.1.0)
devise
faker (~> 1.4.3)
font-awesome-rails (~> 4.3.0.0)
jbuilder (~> 2.0)
jquery-rails
neat
paperclip (~> 4.3)
pg
pry-rails (~> 0.3.4)
rails (= 4.2.2)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/base/_grid-settings.scss
Expand Up @@ -4,7 +4,7 @@
$column: 90px;
$gutter: 50px;
$grid-columns: 12;
$max-width: em(970);
$max-width: em(1200);

// Neat Breakpoints
$medium-screen: em(640);
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/components/_profile.scss
Expand Up @@ -28,6 +28,11 @@
color: #787878;
margin: 0 8px 0 8px;
}
img {
width: 80px;
height: 80px;
border-radius: 50%;
}
}

li.follower_content {
Expand Down
5 changes: 3 additions & 2 deletions app/assets/stylesheets/refills/_cards.scss
Expand Up @@ -4,7 +4,7 @@
//@include justify-content(space-between);
@include span-columns(3);
@include omega(4n);
margin-bottom: 1.5em;
margin-bottom: 10px;
}

.card {
Expand Down Expand Up @@ -38,6 +38,7 @@
cursor: pointer;
position: relative;
position: relative;
width: 100%;

.card-image {
max-height: 150px;
Expand Down Expand Up @@ -72,7 +73,7 @@
text-align: right;
color: #BBBBBB;
line-height: 1em;
padding: .2em ($base-spacing / 2) .5em ($base-spacing /2);
padding: 1.5em ($base-spacing / 2) .5em ($base-spacing /2);
}

&:focus,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me) }
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :password, :remember_me) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Expand Up @@ -47,7 +47,7 @@ def destroy
private

def post_params
params.require(:post).permit(:title, :content)
params.require(:post).permit(:title, :content, :tag_list)
end

def find_post
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/profile_controller.rb
Expand Up @@ -42,6 +42,6 @@ def find_profile
end

def profile_params
params.require(:profile).permit(:tagline, :location, :website, :available)
params.require(:profile).permit(:tagline, :location, :website, :available, :twitter, :avatar)
end
end
29 changes: 29 additions & 0 deletions app/controllers/tags_controller.rb
@@ -0,0 +1,29 @@
class TagsController < ApplicationController
before_action :find_tag

def index
end

def show
end

def new
end

def create
end

def edit
end

def update
end

def destroy
end

private
def find_tag
@tag = Tag.find(params[:id])
end
end
2 changes: 2 additions & 0 deletions app/helpers/tags_helper.rb
@@ -0,0 +1,2 @@
module TagsHelper
end
15 changes: 15 additions & 0 deletions app/models/post.rb
Expand Up @@ -11,6 +11,18 @@ def self.search(query)
end
end

def tag_list
self.tags.collect do |tag|
tag.name
end.join(", ")
end

def tag_list=(tags_string)
tag_names = tags_string.split(",").collect {|tag|tag.strip.downcase}.uniq
new_or_found_tags = tag_names.collect {|name| Tag.find_or_create_by(name: name)}
self.tags = new_or_found_tags
end

validates_presence_of :user_id
validates :title, :content, presence: true
validates_length_of :content, minimum: 1, maximum: 600
Expand All @@ -20,4 +32,7 @@ def self.search(query)

belongs_to :user
has_many :comments

has_many :taggings
has_many :tags, through: :taggings
end
5 changes: 4 additions & 1 deletion app/models/profile.rb
@@ -1,6 +1,9 @@
class Profile < ActiveRecord::Base
belongs_to :user

validates_presence_of :user_id

has_attached_file :avatar, :styles => {:medium => "160x160>"}, :default_url => "/images/:style/default_avatar.gif"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/


end
4 changes: 4 additions & 0 deletions app/models/tag.rb
@@ -0,0 +1,4 @@
class Tag < ActiveRecord::Base
has_many :taggings
has_many :posts, through: :taggings
end
4 changes: 1 addition & 3 deletions app/models/user.rb
Expand Up @@ -2,7 +2,7 @@ class User < ActiveRecord::Base
after_initialize :set_default_role, :if => :new_record?
after_create :create_profile

attr_accessor :login, :tagline, :location, :website, :available
attr_accessor :login, :tagline, :location, :website, :available, :twitter, :avatar
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
Expand All @@ -29,8 +29,6 @@ class User < ActiveRecord::Base
has_one :profile, dependent: :destroy
accepts_nested_attributes_for :profile, allow_destroy: true

#-----------

def set_default_role
self.role ||= :rookie
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_navigation.html.erb
Expand Up @@ -16,7 +16,7 @@
<li class="nav-link more"><%= link_to "#{current_user.username}", "#" %>
<ul class="submenu">
<% if current_user.admin? %>
<li><%= link_to "All Users", users_path %></li>
<li><%= link_to "All Users", "#" %></li>
<% end %>
<li><%= link_to "Profile", profile_path(current_user) %></li>
<li><%= link_to "Edit Profile", edit_profile_path(current_user) %></li>
Expand Down
3 changes: 3 additions & 0 deletions app/views/posts/_form.html.erb
Expand Up @@ -15,6 +15,9 @@
<%= f.label :content %>
<%= f.text_area :content, as: :text, rows: 6 %>
<%= f.label :tag_list %>
<%= f.text_field :tag_list %>
<%= f.submit "Submit" %>
<% end %>
6 changes: 5 additions & 1 deletion app/views/posts/index.html.erb
Expand Up @@ -11,7 +11,11 @@
</a>
</div>
<div class="card-bottom">
temp stuff here
<ul>
<% if post.comments.count > 0 %>
<li><%= fa_icon "comment" %> <%= post.comments.count %></li>
<% end %>
</ul>
</div>
</div>
<div class="card_copy">
Expand Down
6 changes: 6 additions & 0 deletions app/views/posts/show.html.erb
Expand Up @@ -13,6 +13,12 @@
</p>
</div>

<div class="post_tags">
<% @post.tags.each do |tag| %>
<%= link_to tag.name, tag_path(tag) %>
<% end %>
</div>

<div class="response">
<h2><%= pluralize(@post.comments.count, "Response") %></h2>
<hr>
Expand Down
20 changes: 16 additions & 4 deletions app/views/profile/_form.html.erb
Expand Up @@ -8,10 +8,22 @@
<% end %>
</ul>
<% end %>
<%= f.text_field :tagline, placeholder: "Your Tagline", autofocus: true %>
<%= f.text_field :location, placeholder: "Location" %>
<%= f.text_field :website, placeholder: "Website" %>
<span><%= f.label :available, "For Hire?" %><%= f.check_box :available %></span>
<%= f.label :avatar %>
<%= f.file_field :avatar %>
<%= f.label :location %>
<%= f.text_field :location, placeholder: "Anywhere, US" %>
<%= f.label :twitter %>
<%= f.text_field :twitter, placeholder: "@username" %>
<%= f.label :website %>
<%= f.text_field :website, placeholder: "http://" %>
<%= f.label "Bio" %>
<%= f.text_field :tagline %>
<span><%= f.check_box :available %><%= f.label :available, "For Hire?" %></span>

<%= f.submit "Update Profile" %>
Expand Down
12 changes: 11 additions & 1 deletion app/views/profile/edit.html.erb
@@ -1,3 +1,13 @@
<h2><%= "Edit #{current_user.username} Profile" %></h2>
<div class="profile_title">
<h1> <%= link_to "#{current_user.username}", profile_path(current_user) %> / Profile </h1>
</div>

<div class="profile_sections">
<ul>
<li><%= link_to "Profile", profile_path(current_user) %> </li>
<li> <%= link_to "Account Settings", edit_user_registration_path(current_user) %></li>
</ul>
</div>
<hr>

<%= render "form" %>
1 change: 1 addition & 0 deletions app/views/profile/show.html.erb
@@ -1,6 +1,7 @@
<%= render "followers" %>

<div class="profile_head">
<%= image_tag @user.profile.avatar.url(:medium) %>
<h1><%= "#{@profile.user.username}" %></h1>
<h2><%= @user.profile.tagline %></h2>
<span><% if @user.profile.location? %><%= fa_icon "map-marker" %><%= @user.profile.location %><% end %></span>
Expand Down
7 changes: 7 additions & 0 deletions app/views/tags/show.html.erb
@@ -0,0 +1,7 @@
<h1>Posts Tagged with <%= @tag.name %></h1>

<ul>
<% @tag.posts.each do |post| %>
<li><%= link_to post.title, post_path(post) %></li>
<% end %>
</ul>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -4,6 +4,7 @@
resources :posts do
resources :comments
end
resources :tags


devise_for :users, :controllers => { registrations: 'registrations'}
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150814074208_add_twitterr_to_profile.rb
@@ -0,0 +1,5 @@
class AddTwitterrToProfile < ActiveRecord::Migration
def change
add_column :profiles, :twitter, :string
end
end
9 changes: 9 additions & 0 deletions db/migrate/20150814074253_add_avatar_to_profile.rb
@@ -0,0 +1,9 @@
class AddAvatarToProfile < ActiveRecord::Migration
def up
add_attachment :profiles, :avatar
end

def down
remove_attachment :profiles, :avatar
end
end

0 comments on commit f1329e3

Please sign in to comment.