First. Add some new routes:
resources :highlights, :controller => "ads", :type => "Highlight"
resources :bargains, :controller => "ads", :type => "Bargain"
And fix some actions in AdsController
. For example:
def new
@ad = Ad.new()
@ad.type = params[:type]
end
For best approach for all this controller job look this comment
That’s all. Now you can go to localhost:3000/highlights/new
and new Highlight
will be initialized.
Index action can look like this:
def index
@ads = Ad.where(:type => params[:type])
end
Go to localhost:3000/highlights
and list of highlights will appear.
Same way for bargains: localhost:3000/bargains
etc
URLS
<%= link_to 'index', :highlights %>
<%= link_to 'new', [:new, :highlight] %>
<%= link_to 'edit', [:edit, @ad] %>
<%= link_to 'destroy', @ad, :method => :delete %>
for being polymorphic 🙂
<%= link_to 'index', @ad.class %>