From f90dca555247651c580f879a22d932f378a34ce9 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 6 Sep 2009 19:35:12 +0200 Subject: added public search controller with corresponding view --- app/controllers/search_controller.rb | 11 +++++++++++ app/helpers/search_helper.rb | 2 ++ app/views/search/index.html.erb | 19 +++++++++++++++++++ config/routes.rb | 1 + test/functional/search_controller_test.rb | 8 ++++++++ test/unit/helpers/search_helper_test.rb | 4 ++++ 6 files changed, 45 insertions(+) create mode 100644 app/controllers/search_controller.rb create mode 100644 app/helpers/search_helper.rb create mode 100644 app/views/search/index.html.erb create mode 100644 test/functional/search_controller_test.rb create mode 100644 test/unit/helpers/search_helper_test.rb 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 @@ +class SearchController < ApplicationController + def index + @page = Page.new + search_term = params[:search_term] + if search_term and not search_term.empty? + nodes = Node.search(params[:search_term]) + @results = nodes.map {|node| node.head} + end + end + +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 @@ +module SearchHelper +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 @@ +

Suche

+ +<% form_tag search_path, :method => 'get' do %> + <%= text_field_tag :search_term %> + <%= submit_tag "Suchen" %> +<% end %> + + +<% if params[:search_term] %> +

Suchergebnisse für Suchbegriff: <%= params[:search_term] %>

+<% end %> + +<%= + render( + :partial => 'custom/partials/article', + :collection => @results, + :as => :page + ) +%> \ 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| map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' map.admin_search 'admin/search', :controller => 'admin', :action => 'search' + map.search 'search', :controller => "search", :action => 'index' map.resources :users map.resources :menu_items, :member => {:sort => :post} 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 @@ +require 'test_helper' + +class SearchControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +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 @@ +require 'test_helper' + +class SearchHelperTest < ActionView::TestCase +end -- cgit v1.3