alex lug alex lug - 1 year ago 59
Ruby Question

routes issues in layout

Ok so i'm getting this error -
No route matches {:action=>"search", :controller=>"drawings", :search=>"2016"} missing required keys: [:workcategory_id]

I have this in my layouts/_header

<% unless @workcategories.nil? %>
<% @workcategories.each do |workcategory| %>
<li><%= link_to, search_workcategory_drawings_path(search: %></li>
<% end %>

my drawing model

belongs_to :workcategory
drawings = Drawing.where("name like ?", "%#{params[:search]}%")

and this is the part of the controller where things should be happening

def search
@drawings =

lastly my routes

resources :workcategories do
resources :drawings do
collection do
get :search

So the issue is, that when i go on any page - home, admin panel etc .. i get that error 'No route matches {:action=>"search", :controller=>"drawings", :search=>"2016"} missing required keys: [:workcategory_id]'. I don't understand why it's trying to 'build' the search path already, although i'm not trying to access it. I hope i'm making sense ...

Answer Source

Simply provide a workcategory_id :

      <li><%= link_to, search_workcategory_drawings_path(, search: %></li>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download