diff options
| author | hukl <contact@smyck.org> | 2009-09-06 19:35:12 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-06 19:35:12 +0200 |
| commit | f90dca555247651c580f879a22d932f378a34ce9 (patch) | |
| tree | 9804d294a92a32a38e5ac5cb3a6ced8ab1c5729e | |
| parent | 54543aeb8a1cebdffa96a6ac4b98baa6c1b8747d (diff) | |
added public search controller with corresponding view
| -rw-r--r-- | app/controllers/search_controller.rb | 11 | ||||
| -rw-r--r-- | app/helpers/search_helper.rb | 2 | ||||
| -rw-r--r-- | app/views/search/index.html.erb | 19 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | test/functional/search_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/unit/helpers/search_helper_test.rb | 4 |
6 files changed, 45 insertions, 0 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb new file mode 100644 index 0000000..97ecdfd --- /dev/null +++ b/app/controllers/search_controller.rb | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | class SearchController < ApplicationController | ||
| 2 | def index | ||
| 3 | @page = Page.new | ||
| 4 | search_term = params[:search_term] | ||
| 5 | if search_term and not search_term.empty? | ||
| 6 | nodes = Node.search(params[:search_term]) | ||
| 7 | @results = nodes.map {|node| node.head} | ||
| 8 | end | ||
| 9 | end | ||
| 10 | |||
| 11 | end | ||
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb new file mode 100644 index 0000000..b3ce20a --- /dev/null +++ b/app/helpers/search_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module SearchHelper | ||
| 2 | end | ||
diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb new file mode 100644 index 0000000..2e46d20 --- /dev/null +++ b/app/views/search/index.html.erb | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | <h2>Suche</h2> | ||
| 2 | |||
| 3 | <% form_tag search_path, :method => 'get' do %> | ||
| 4 | <%= text_field_tag :search_term %> | ||
| 5 | <%= submit_tag "Suchen" %> | ||
| 6 | <% end %> | ||
| 7 | |||
| 8 | |||
| 9 | <% if params[:search_term] %> | ||
| 10 | <h3>Suchergebnisse für Suchbegriff: <%= params[:search_term] %></h3> | ||
| 11 | <% end %> | ||
| 12 | |||
| 13 | <%= | ||
| 14 | render( | ||
| 15 | :partial => 'custom/partials/article', | ||
| 16 | :collection => @results, | ||
| 17 | :as => :page | ||
| 18 | ) | ||
| 19 | %> \ No newline at end of file | ||
diff --git a/config/routes.rb b/config/routes.rb index c3b2e84..1706dad 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
| @@ -18,6 +18,7 @@ ActionController::Routing::Routes.draw do |map| | |||
| 18 | map.logout '/logout', :controller => 'sessions', :action => 'destroy' | 18 | map.logout '/logout', :controller => 'sessions', :action => 'destroy' |
| 19 | map.login '/login', :controller => 'sessions', :action => 'new' | 19 | map.login '/login', :controller => 'sessions', :action => 'new' |
| 20 | map.admin_search 'admin/search', :controller => 'admin', :action => 'search' | 20 | map.admin_search 'admin/search', :controller => 'admin', :action => 'search' |
| 21 | map.search 'search', :controller => "search", :action => 'index' | ||
| 21 | map.resources :users | 22 | map.resources :users |
| 22 | map.resources :menu_items, :member => {:sort => :post} | 23 | map.resources :menu_items, :member => {:sort => :post} |
| 23 | map.resource :session | 24 | map.resource :session |
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb new file mode 100644 index 0000000..49bb14f --- /dev/null +++ b/test/functional/search_controller_test.rb | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class SearchControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/unit/helpers/search_helper_test.rb b/test/unit/helpers/search_helper_test.rb new file mode 100644 index 0000000..3034163 --- /dev/null +++ b/test/unit/helpers/search_helper_test.rb | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class SearchHelperTest < ActionView::TestCase | ||
| 4 | end | ||
