I have a car model:
Routes
map.resources :vehicles, :has_many => :suppliers
Everything works fine, but the vehicle has the is_truck boolean attribute . I want to create an alias so that I can get the same resources by filtering only trucks, I tried:
Routes
map.trucks '/trucks', :controller => :vehicles, :action => :index, :is_truck => true
map.trucks '/trucks/by_supplier/:supplier', :controller => :vehicles, :action => :index, :is_truck => true
The first one works well, but when I search on the Form, the second one does not work and searches for all suppliers.
Controller:
class VehiclesController
def index
if params[:supplier]
@vehicles = Vehicle.all :conditions => { :is_truck => params[:is_truck] }
else
@vehicles = Vehicle.all
end
end
...
end
Search Form:
<% form_for :truck, :url => {:controller => :trucks, :action => :index}, :html => {:method => :get} do |f| %>
<% f.text_field :search %>
<% f.submit 'Search Trucks' %>
<% end %>
Is map.resources possible as an alias?
source
share