Skip to content

Commit

Permalink
Beginnings of search functionality
Browse files Browse the repository at this point in the history
 -Adds a search model
 -Adds create/show routes
 -Updates the application layout to use form_for for the
  search input
  • Loading branch information
Brent Collier committed Nov 4, 2012
1 parent 61ac682 commit b0c7c0a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
15 changes: 4 additions & 11 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
module ApplicationHelper

def stalker_links
{"facebook" => "http://facebook.com/brentcollier",
"github" => "http://github.com/brentmc79",
"flickr" => "http://flickr.com/brentmc79",
"foursquare" => "https://foursquare.com/brentmc79",
"amazon" => "http://amzn.com/w/11UI8DE8EV7NO",
"linkedin" => "http://www.linkedin.com/in/brentcollier",
"vimeo" => "http://vimeo.com/brentmc79",
"twitter" => "http://twitter.com/brentmc79"}
end

def tag_links
@tag_links ||= ActsAsTaggableOn::Tag.all.map do |tag|
count = ActsAsTaggableOn::Tagging.where(:tag_id => tag.id).count
Expand All @@ -27,4 +16,8 @@ def other_posts
@other_Posts = Post.where("\"posts\".\"id\" NOT IN (?)",visible_posts).order("created_at desc").all
end

def search
@search || Search.new
end

end
17 changes: 17 additions & 0 deletions app/models/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Search
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :query, :results

def initialize(attributes={})
attributes.each do |name, value|
send("#{name}=", value)
end
end

def persisted?
false
end
end
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@
<div class="span3">
<div class="well sidebar-nav">
<form class="form-search">
<%= form_for search do |f| %>
<div class="input-append">
<input type="text" class="span2 search-query">
<%= f.text_field :query, :class => "span2 search-query" %>
<button id="search-submit" type="submit" class="btn">Search</button>
</div>
</form>
<% end %>
<div class="alert alert-info alert-block">
<!--<p>I'm <span class="label label-info">Brent Collier</span>.</p>-->
<p>I'm <strong>Brent Collier</strong>.</p>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
end

resources :posts, :only => [:index, :show]
resources :searches, :only => [:create, :show]

root :to => "posts#index"

Expand Down

0 comments on commit b0c7c0a

Please sign in to comment.