-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Michelle #6
base: master
Are you sure you want to change the base?
Michelle #6
Changes from all commits
b4830af
4c6c606
af22fea
fcf2bbf
29da30f
15c78e2
72ea1cd
5d903c1
453aba7
909ef24
9a95dc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import "bootstrap-sprockets"; | ||
@import "bootstrap"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Core variables and mixins | ||
@import "bootstrap/variables"; | ||
@import "bootstrap/mixins"; | ||
|
||
// Reset and dependencies | ||
@import "bootstrap/normalize"; | ||
@import "bootstrap/print"; | ||
@import "bootstrap/glyphicons"; | ||
|
||
// Core CSS | ||
@import "bootstrap/scaffolding"; | ||
@import "bootstrap/type"; | ||
@import "bootstrap/code"; | ||
@import "bootstrap/grid"; | ||
@import "bootstrap/tables"; | ||
@import "bootstrap/forms"; | ||
@import "bootstrap/buttons"; | ||
|
||
// Components | ||
@import "bootstrap/component-animations"; | ||
@import "bootstrap/dropdowns"; | ||
@import "bootstrap/button-groups"; | ||
@import "bootstrap/input-groups"; | ||
@import "bootstrap/navs"; | ||
@import "bootstrap/navbar"; | ||
@import "bootstrap/breadcrumbs"; | ||
@import "bootstrap/pagination"; | ||
@import "bootstrap/pager"; | ||
@import "bootstrap/labels"; | ||
@import "bootstrap/badges"; | ||
@import "bootstrap/jumbotron"; | ||
@import "bootstrap/thumbnails"; | ||
@import "bootstrap/alerts"; | ||
@import "bootstrap/progress-bars"; | ||
@import "bootstrap/media"; | ||
@import "bootstrap/list-group"; | ||
@import "bootstrap/panels"; | ||
@import "bootstrap/responsive-embed"; | ||
@import "bootstrap/wells"; | ||
@import "bootstrap/close"; | ||
|
||
// Components w/ JavaScript | ||
@import "bootstrap/modals"; | ||
@import "bootstrap/tooltip"; | ||
@import "bootstrap/popovers"; | ||
@import "bootstrap/carousel"; | ||
|
||
// Utility classes | ||
@import "bootstrap/utilities"; | ||
@import "bootstrap/responsive-utilities"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="user_info"> | ||
<img src="<%=user.photo_url%>"> <a href="/user/<%=user.id%>"><%user.name%></a> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
before "/bite/:id/edit" do | ||
@bite = Bite.find(params[:id]) | ||
@authorized = true if current_user == User.find(@bite.author) | ||
end | ||
|
||
get "/bite/:id/edit" do | ||
if @authorized != true | ||
redirect to "user/#{session[:user_id]}/bitefeed" | ||
end | ||
erb :'/bites/edit' | ||
end | ||
|
||
put "/bite/:id/edit" do | ||
@bite.update(content: params[:bite_content]) | ||
#CHECK FOR NEW HASHTAGS AND DESTROY FROM OLD | ||
#check_for_hashtags(@bite) | ||
|
||
redirect to "user/#{session[:user_id]}/bitefeed" | ||
end | ||
|
||
delete "/bite/:id" do | ||
Bite.find(params[:id]).destroy | ||
|
||
redirect to "user/#{session[:user_id]}/bitefeed" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
get '/hashtag/:id' do | ||
@tag = Hashtag.find(params[:id]) | ||
@bites_for_tag = @tag.bites | ||
|
||
erb :'hashtags/show' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,64 @@ | ||
require 'json' | ||
|
||
before '/user/:id/bitefeed' do | ||
@authorized = true if current_user == User.find(params[:id]) | ||
end | ||
|
||
get "/user/:id" do | ||
@user = User.find(params[:id]) | ||
@bites = @user.bites | ||
@followers = @user.followers | ||
@followed_users = | ||
@bites = @user.bites.order("created_at DESC") | ||
following?(@user) ? @btn_display = "UNBite Me" : @btn_display = "Bite Me" | ||
|
||
erb :'users/show' | ||
end | ||
|
||
get "/user/:id/newsfeed" do | ||
post "/user/:id" do | ||
@user = User.find(session[:user_id]) | ||
@user_on_page = User.find(params[:id]) | ||
if following?(@user_on_page) | ||
|
||
@user.followed_relationships.find_by(followed_user_id: params[:id]).destroy | ||
erb :'/partials/_follow_info', layout: false | ||
else | ||
@user.followed_users << @user_on_page | ||
erb :'/partials/_follow_info', layout: false | ||
end | ||
end | ||
|
||
$PLACEHOLDER_SAYINGS = ["Everyone is so interested in what you're eating...", "Whatcha biting on?", "Yum that looks good, you should tell everyone!", "Nom Nom Nom", "Don't forget to #foodporn", "Everyone's going to be so jealous when they see this.", "Oh, I'm so interested, please tell me more."] | ||
|
||
get "/user/:id/bitefeed" do | ||
if @authorized == false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
redirect to ("/user/#{session[:user_id]}/bitefeed") | ||
end | ||
|
||
@user = User.find(session[:user_id]) | ||
@bite_feed = followers_bites | ||
@trending_hashtags = trending_hashtags | ||
|
||
erb :'users/bitefeed' | ||
end | ||
|
||
post "/user/:id/new" do | ||
@user = User.find(session[:user_id]) | ||
@bite = @user.bites.create(content: params[:bite_content]) | ||
|
||
erb :'/partials/_bite_display', locals: {bite: @bite}, layout: false | ||
end | ||
|
||
get "/user/:id/followers" do | ||
@user = User.find(params[:id]) | ||
@users_followers = User.find(params[:id]).followers | ||
@followers = @users_followers - [@user] | ||
@users_following = User.find(params[:id]).followed_users | ||
@following = @users_following - [@user] | ||
|
||
erb :'users/followers' | ||
end | ||
|
||
# get "/user/:id/following" do | ||
# @user = User.find(params[:id]) | ||
# @followers = [] | ||
|
||
# erb :'users/followers' | ||
# end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,32 @@ def current_user | |
def logged_in? | ||
!current_user.nil? | ||
end | ||
|
||
def following?(bite_user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this belongs in a model? |
||
user = User.find(session[:user_id]) | ||
following = user.followed_users.select {|followed_user| followed_user == bite_user} | ||
following.length == 0 ? false : true | ||
end | ||
|
||
def followers_bites | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this goes in a model too? |
||
bite_feed = [] | ||
logged_in_user = User.find(session[:user_id]) | ||
logged_in_user.followed_users.each {|user| bite_feed << user.bites.order("created_at DESC")} | ||
# bite_feed.sort_by {|bite| bite.created_at} | ||
bite_feed.flatten | ||
end | ||
|
||
def check_for_hashtags(bite_object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also model? |
||
bite_object.content.split(" ").each do |word| | ||
if Hashtag.exists?(current_user.bites.find(bite_object.id).hashtags.find_by(hashtag: word.match(/#\w{0,}/).to_s)) == false | ||
bite_object.hashtags << Hashtag.find_or_create_by(hashtag: word.match(/#\w{0,}/).to_s) if word[0] == "#" | ||
end | ||
end | ||
end | ||
|
||
def trending_hashtags | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also model? |
||
Hashtag.all.order("bites_count DESC").limit(5) | ||
end | ||
end | ||
|
||
# User.order("users.solutions_count DESC").limit(10) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class Bite < ActiveRecord::Base | ||
belongs_to :user | ||
# Remember to create a migration! | ||
belongs_to :author, class_name: "User", foreign_key: :user_id | ||
has_many :bite_hashtags | ||
has_many :hashtags, through: :bite_hashtags | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class BiteHashtag < ActiveRecord::Base | ||
belongs_to :bite, counter_cache: :hashtags_count | ||
belongs_to :hashtag, counter_cache: :bites_count | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Hashtag < ActiveRecord::Base | ||
has_many :bite_hashtags | ||
has_many :bites, through: :bite_hashtags | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try
if ! User.exists?
or
unless User.exists?