Skip to content
Browse files

Filter link columns by type t:35m

  • Loading branch information...
1 parent 457ea61 commit 78b02b0eae619d97c24f6d8ce649589285935e87 Will McNeilly committed Sep 15, 2011
Showing with 14 additions and 12 deletions.
  1. +4 −3 app/controllers/links_controller.rb
  2. +10 −9 app/views/links/index.html.erb
View
7 app/controllers/links_controller.rb
@@ -1,9 +1,10 @@
class LinksController < ApplicationController
def index
- @popular = Link.popular
- @recent = Link.recent
- @my_links = Link.by_session_id(session[:session_id])
+ @filter = params[:filter] ||= "my_links"
+ @popular = Link.popular if params[:filter] == "popular"
+ @recent = Link.recent if params[:filter] == "recent"
+ @my_links = Link.by_session_id(session[:session_id]) if params[:filter] == "my_links"
@link = Link.new
end
View
19 app/views/links/index.html.erb
@@ -3,16 +3,17 @@
<%= render :partial => "form" %>
</div>
</div>
-<div class="container">
- <%- if @popular.size > 0 -%>
- <%= render 'links', :links => @popular %>
- <%- end -%>
-
- <%- if @my_links.size > 0 -%>
+<div class="container<%= " #{@filter}" %>">
+ <ul>
+ <li><%= link_to "My Squishes", :filter => "my_links" %></li>
+ <li><%= link_to "Recently Squished", :filter => "recent" %></li>
+ <li><%= link_to "Popular Squishes", :filter => "popular" %></li>
+ </ul>
+ <%- if @filter == "my_links" %>
<%= render 'links', :links => @my_links %>
- <%- end -%>
-
- <%- if @recent.size > 0 -%>
+ <%- elsif @filter == "popular" %>
+ <%= render 'links', :links => @popular %>
+ <%- elsif @filter == "recent" %>
<%= render 'links', :links => @recent %>
<%- end -%>
</div>

0 comments on commit 78b02b0

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