Skip to content
Browse files

end of day tuesday

  • Loading branch information...
1 parent 460b706 commit c136616435f4cae94cb119f9d750e079e5bf8da0 @drapergeek committed Mar 13, 2012
View
2 app/controllers/dashboards_controller.rb
@@ -2,6 +2,6 @@ class DashboardsController < ApplicationController
def show
@text_shout = TextShout.new
@photo_shout = PhotoShout.new
- @shouts = current_user.shouts.current
+ @shout_feed = current_user.shout_feed_for_self_and_followed_users
end
end
View
10 app/controllers/searches_controller.rb
@@ -0,0 +1,10 @@
+class SearchesController < ApplicationController
+
+ def show
+ if params[:search]
+ @shouts = Shout.search(params[:search])
+ else
+ redirect_to root_url
+ end
+ end
+end
View
4 app/controllers/users_controller.rb
@@ -1,8 +1,8 @@
class UsersController < ApplicationController
def show
- @user = User.find(params[:id])
- @shouts = @user.shouts.current
+ @user = User.find(params[:id])
+ @shout_feed = @user.shout_feed
@following_relationship = FollowingRelationship.new(:followed_user_id=>@user.id)
end
end
View
7 app/models/shout.rb
@@ -7,4 +7,11 @@ class Shout < ActiveRecord::Base
def self.current
order("created_at DESC")
end
+
+ def self.search(search)
+ text_shouts = TextShout.where("UPPER(body) LIKE ?", "%#{search.upcase}%").collect(&:shout)
+ photo_shouts = PhotoShout.where("UPPER(photo_file_name) LIKE ?", "%#{search.upcase}%").collect(&:shout)
+ shouts = text_shouts + photo_shouts
+ end
+
end
View
12 app/models/shout_feed.rb
@@ -0,0 +1,12 @@
+class ShoutFeed
+ extend ActiveModel::Naming
+
+ def initialize(user_ids)
+ @user_ids = user_ids
+ end
+
+ def shouts
+ Shout.where(user_id: @user_ids).current.includes(:user, {:medium=>:shout})
+ end
+
+end
View
11 app/models/user.rb
@@ -9,6 +9,15 @@ class User < ActiveRecord::Base
has_many :followers, through: :following_user_relationships, source: :following_user
+ def shout_feed_for_self_and_followed_users
+ ShoutFeed.new(self_and_followed_user_ids)
+ end
+
+ def shout_feed
+ ShoutFeed.new(id)
+ end
+
+
def create_shout(medium)
new_shout = shouts.create(medium: medium)
end
@@ -27,6 +36,6 @@ def can_unfollow?(user)
private
def self_and_followed_user_ids
- [id] + followed_user_ids
+ [id] + followed_user_ids
end
end
View
25 app/views/dashboards/show.html.erb
@@ -1,16 +1,15 @@
-<h1>Dashboard</h1>
-<p>Welcome <%= current_user.email %>! <%= link_to "Sign Out", sign_out_path, method: :delete %></p>
-<%= form_for @text_shout do |f| %>
- <%= f.text_field :body, placeholder: "Shout here" %>
- <%= f.submit "Shout!" %>
-<% end %>
+<div class="row">
+ <div class="span4">
+ <strong>Add a photo shout</strong>
+ <%= form_for @photo_shout do |f| %>
+ <%= f.file_field :photo %>
+ <%= f.submit "Shout!" %>
+ <% end %>
-<strong>Add a photo shout</strong>
-<%= form_for @photo_shout do |f| %>
- <%= f.file_field :photo %>
- <%= f.submit "Shout!" %>
-<% end %>
+ </div>
+
+ <div class="span8">
+ <%= render @shout_feed %>
+ </div>
-<div id="shouts">
- <%= render @shouts %>
</div>
View
20 app/views/layouts/application.html.erb
@@ -15,11 +15,20 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
- <%= link_to "Shouter",root_url, :class=>"brand" %>
- <div class="nav-collapse">
- <ul class="nav">
- </ul>
- </div>
+ <%= link_to "Shouter", root_url, :class=>"brand" %>
+ <%= form_tag search_path, :method=>:get, :class=>"navbar-form pull-left" do %>
+ <%= text_field_tag :search, params[:search], placeholder: "Search here" %>
+ <% submit_tag %>
+ <% end %>
+ <ul class="nav pull-right">
+ <li>
+ <%= link_to "Welcome #{current_user.email}", current_user %>
+ </li>
+ <li class="divider-vertical"></li>
+ <li>
+ <%= link_to "Sign Out", sign_out_path, method: :delete %>
+ </li>
+ </ul>
</div>
</div>
</div>
@@ -32,7 +41,6 @@
</div>
<% end %>
-
<%= yield %>
</div>
View
2 app/views/photo_shouts/_photo_shout.html.erb
@@ -1 +1 @@
-<%= link_to image_tag(photo_shout.photo.url(:thumb)), photo_shout.shout %> <%= time_ago_in_words(photo_shout.shout.created_at) %> ago
+<%= link_to image_tag(photo_shout.photo.url(:thumb)), photo_shout.shout %>
View
9 app/views/searches/show.html.erb
@@ -0,0 +1,9 @@
+<div class="row">
+ <div class="span9">
+ <% if @shouts.empty? %>
+ No shouts found
+ <% else %>
+ <%= render @shouts %>
+ <% end %>
+ </div>
+</div>
View
3 app/views/shout_feeds/_shout_feed.html.erb
@@ -0,0 +1,3 @@
+<ul id="shouts" class="nav nav-pills nav-stacked">
+ <%= render shout_feed.shouts %>
+</ul>
View
7 app/views/shouts/_shout.html.erb
@@ -1,3 +1,6 @@
-<%= content_tag_for(:div, shout) do %>
- <%= render shout.medium %>
+<%= content_tag_for(:li, shout) do %>
+
+ <div><%= render shout.medium %></div>
+ <div><%= link_to shout.user.email, shout.user %> <%= time_ago_in_words(shout.created_at) %></div>
+
<% end %>
View
2 app/views/text_shouts/_text_shout.html.erb
@@ -1 +1 @@
-<%= link_to text_shout.body, text_shout.shout %> <%= time_ago_in_words(text_shout.shout.created_at) %> ago
+<%= text_shout.body %>
View
10 app/views/users/show.html.erb
@@ -1,7 +1,5 @@
<h1><%= @user.email %></h1>
-<div id="shouts">
- <%= render @shouts %>
- <% if can_follow @user %>
- <%= button_to "Follow", user_following_relationships_path(@user), class: "btn btn-warning" %>
- <% end %>
-</div>
+<% if @user.can_follow? @user %>
+ <%= button_to "Follow", user_following_relationships_path(@user), class: "btn btn-warning" %>
+<% end %>
+<%= render @shout_feed %>
View
1 config/routes.rb
@@ -6,6 +6,7 @@
resources :users, only: [:show] do
resources :following_relationships, only: [:create]
end
+ resource :search, only: [:show]
root to: "welcome#index"
end
View
5 spec/factories.rb
@@ -9,4 +9,9 @@
shout
end
+ factory :photo_shout do
+ photo_file_name "blue.jpg"
+ shout
+ end
+
end
View
14 spec/models/shout_spec.rb
@@ -6,4 +6,18 @@
newer_shout = create(:shout)
Shout.current.should == [newer_shout, older_shout]
end
+
+ it "returns shouts from #search" do
+ upcase_shout = create(:text_shout, :body=>"Blue").shout
+ downcase_shout = create(:text_shout, :body=>"blue").shout
+ non_search_shout = create(:text_shout, :body=>"green").shout
+ photo_shout = create(:photo_shout, :photo_file_name=>"blue.jpg").shout
+ non_search_photo_shout = create(:photo_shout, :photo_file_name=>"green.jpg").shout
+
+ Shout.search("blue").include?(upcase_shout).should == true
+ Shout.search("blue").include?(downcase_shout).should == true
+ Shout.search("blue").include?(non_search_shout).should == false
+ Shout.search("blue").include?(photo_shout).should == true
+ Shout.search("blue").include?(non_search_photo_shout).should == false
+ end
end

0 comments on commit c136616

Please sign in to comment.
Something went wrong with that request. Please try again.