Search code examples
ruby-on-railsrubyroutesformtastic

Why am I getting "you may have ambiguous routes" for a rails controller action?


I am having trouble with a semantic form for one of my models. The relevant models are

class Event < ActiveRecord::Base
  belongs_to :series
  ...
end

class Series < ActiveRecord::Base
  has_many :events
  ...
end

When I visit /series/new in a browser, I get the error:

 series_url failed to generate from {:controller=>"series", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: ["series", :id] - are they all satisfied?

EDIT: I have run rake routes | grep series | grep new to look for conflicting routes, and there are none, here is the output:

new_series_event GET /series/:series_id/events/new(.:format) {:controller=>"events", :action=>"new"} 
new_series       GET /series/new(.:format) {:controller=>"series", :action=>"new"}

The template corresponding to the /series/new renders the following partial:

<% semantic_form_for(@series) do |f| %>
  <%= f.error_messages %>
  <% f.inputs do %>
    <%= f.input :title %>
    <%= f.input :uri, :label => "URL of the Series", :hint => "For example, use 'tes' for 'Transportation Education Series'. It will appear as http://events.kittelson.com/tes"    <%= f.input :description %>
    <%= f.input :contact, :label => "Contact email" %>
    <%= f.input :color, :label => "Pick a dark color" %>
  <% end %>
  <% f.buttons do %>
    <%= f.commit_button %>
    <%= link_to "or cancel", :back %>
  <% end %>
<% end %>

Where the @series object is defined in the controller as Series.new.

What I don't understand is how this relates to routing, I ran rake routes and there is only one controller action mapped to /series/new.

Here is the part of config/routes.rb that relates to these models:

ActionController::Routing::Routes.draw do |map|
  map.resources :series, :has_many => :events
  map.resources :events, :has_many  => :rsvps
end

What could be causing this routing error?


Solution

  • Just a hunch. You might be confusing Rail's inflector. Maybe it should be belongs_to serial instead of belongs_to series?

    You see, normally we would write belongs_to user rather than users. So you might want to try that out.