Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added not working search

  • Loading branch information...
commit 506fa92b17aa290c023610943ced329a64aab59b 1 parent ab2a4fc
Arina Neshlyaeva authored
View
1  .gitignore
@@ -6,3 +6,4 @@ doc/app
coverage
db/*.sqlite3
*.swp
+*~
View
18 app/controllers/search_controller.rb
@@ -0,0 +1,18 @@
+require 'pp'
+class SearchController < ApplicationController
+
+
+ def index
+ @book = Book.new
+ end
+
+ def create
+ @books = []
+ pp params[:book][:title]
+ params[:book][:title].split.each do |word|
+ pp "word >>#{word}<<"
+ pp Book.find(word)
+ pp "books >>#{@books}<<"
+ end
+ end
+end
View
2  app/helpers/search_helper.rb
@@ -0,0 +1,2 @@
+module SearchHelper
+end
View
14 app/views/search/create.html.erb
@@ -0,0 +1,14 @@
+<h1>Search results</h1>
+
+<table>
+ <tr>
+ <th>Title</th>
+ </tr>
+
+<% for book in @books %>
+ <tr>
+ <td><%=h book.title %></td>
+ <td><%= link_to 'Show', book %></td>
+ </tr>
+<% end %>
+</table>
View
31 app/views/search/index.html.erb
@@ -0,0 +1,31 @@
+<h1>Search</h1>
+
+<% form_for @book, :url => {:action => :create} do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :title %><br />
+ <%= f.text_field :title %>
+ </p>
+ <p>
+ <%= f.label :publisher %><br />
+ <%= f.text_field :publisher %>
+ </p>
+ <p>
+ <%= f.label :year %><br />
+ <%= f.text_field :year %>
+ </p>
+ <p>
+ <%= f.label :isbn %><br />
+ <%= f.text_field :isbn %>
+ </p>
+ <p>
+ <%= f.label :series %><br />
+ <%= f.text_field :series %>
+ </p>
+ <p>
+ <%= f.submit "Search" %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', books_path %>
View
3  config/routes.rb
@@ -1,5 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :books
+ map.resource :search
# Restful Authentication Rewrites
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
@@ -16,7 +17,7 @@
map.resources :users
map.resources :passwords
map.resource :session
-
+
# Home Page
map.root :controller => 'sessions', :action => 'new'
View
10 spec/controllers/search_controller_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe SearchController do
+
+ #Delete this example and add some real ones
+ it "should use SearchController" do
+ controller.should be_an_instance_of(SearchController)
+ end
+
+end
View
11 spec/helpers/search_helper_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe SearchHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should be included in the object returned by #helper" do
+ included_modules = (class << helper; self; end).send :included_modules
+ included_modules.should include(SearchHelper)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.