Wyszukiwarka - problem

Witam wszystkich!

Pytanie proste pewnie dla większości z Was mianowicie utknąłem na formularzu wyszukiwania, proszę o pomoc - posiłkowałem się w tworzeniu rails guides

  1. Po stronie widoku mam
<% form_for(search_path, :method => "get") do %>
  <%= label_tag(:q, "Search for:") %>
  <%= text_field_tag(:q) %>
  <%= submit_tag("Seaaaarch!") %>
<% end %>
  1. Plus w routes mam
  map.search “search”, :controller => “search”

No i właśnie w tym miejscu serwer się wysypuje z:

        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:
16:in `reload!'                                                                                                   
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:
26:in `block in updater'                                                                                          
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.13/lib/active_support/file_update_check
er.rb:78:in `call'                                                                                                
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.13/lib/active_support/file_update_check
er.rb:78:in `execute'                                                                                             
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:
27:in `updater'                                                                                                   
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:
7:in `execute_if_updated'                                                                                         
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application/finisher.rb:66:in `
block in <module:Finisher>'                                                                                       
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instanc
e_exec'                                                                                                           
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'   
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block i
n run_initializers'                                                                                               
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'  
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_ini
tializers'                                                                                                        
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/application.rb:136:in `initiali
ze!'                                                                                                              
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `
method_missing'                                                                                                   
        from /home/action/Workout/config/environment.rb:5:in `<top (required)>'                                   
        from /home/action/Workout/config.ru:3:in `require'                                                        
        from /home/action/Workout/config.ru:3:in `block in <main>'                                                
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'     
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'        
        from /home/action/Workout/config.ru:in `new'                                                              
        from /home/action/Workout/config.ru:in `<main>'                                                           
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'              
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'        
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'               
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app' 
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'       
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'             
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start
'                                                                                                                 
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <to
p (required)>'                                                                                                    
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'        
        from /home/action/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (requir
ed)>'                                                                                                             
        from script/rails:6:in `require'                                                                          
        from script/rails:6:in `<main>'                                                    

z góry dzięki za pomoc

całe repo na - https://github.com/rediver/workout-test

get 'search', to: 'client_workouts#search', as: :search

Ew. zamiast , to: może być =>

czemu tak? :slight_smile: dzięki za z góry odpowiedź to dla mnie cenna nauka

Tak to się w rails 2.x pisało mniej więcej, a i tak źle, bo controller to client_workouts, a search action :wink:
Nawet w swoim pliku routes.rb masz taki fragment:

# Sample of named route:
#   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

A stosowanie na początku get/put/delete/post/patch zamiast match to praktyka zalecana z kolei w rails 4.

1 Like

czyli tłumacząc trochę łopatologicznie

weź ścieżkę search, do niej przypisz z kontrolera akcje client_workouts#search i as(??) :slight_smile: dobrze rozumiem?

Jeżeli aplikacja dostanie żądanie url wysłane pod adres /search metodą GET, to ma wykonać metodę search z kontrolera client_workouts, natomiast z poziomu aplikacji, ta ścieżka ma być dostępna pod aliasem search_path bądź search_url.

get w tym przypadku nie możesz interpretować jako “weź”. To jest czasownik HTTP, tak jak wcześniej pisałem.

Przestudiuj http://guides.rubyonrails.org/routing.html