Rails: ActionController::RoutingError No route matches error

I have a search controller (no model) where I am running a query against the Users table. It works completely fine, but once i enter this

<%= link_to "Good to proceed now.", new_user_product_path, :class => "btn" %>

It gives me

ActionController::RoutingError (No route matches {:action=>"new", :controller=>"products"}):

I already have relationship estbalished between the User and product model. I am able to access the products#new when I directly go to the link http://127.0.0.1:3000/users/3/products/new. But again, when the link_to snippet is entered, it gives the above error.

My search is controller isnt tied up with the db, it just helps me process the front end.

What am i doing wrong here? Is there something I need to do with the routes?

here is my routes file

  resources :searches, only: [:index, :create]
  resources :users do 
      resources :products 
  end

Answers


You need to pass the user to the new_user_product_path.

So something like:

new_user_product_path(@user) or new_user_product_path(current_user)


Need Your Help

jquery ui dynamic icon

javascript jquery jquery-ui button

I have a set of buttons and Im trying to instead of setting individual icons for them, use an attribute and one-for-all function to set their icon. Here is an example of my button :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.