Equipment_URL Failed to Generate (new_equipment_path)

I’m trying to use new_equipment_path, which creates the appropriate
link. But, when trying to evaluate “equipment/new” I get the error
below. I’ve included my routes (rake route). Equipment is one of those
words that pluralizes to “equipment”, so the singular is right (from
what I know from this forum.

Any help would be appreciated.

Error:

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

Routes:

 equipment_index GET    /equipment

(.:format)
{:controller=>“equipment”, :action=>“index”}
POST /equipment
(.:format)
{:controller=>“equipment”, :action=>“create”}
new_equipment GET /equipment/new
(.:format)
{:controller=>“equipment”, :action=>“new”}
edit_equipment GET /equipment/:id/edit
(.:format)
{:controller=>“equipment”, :action=>“edit”}
equipment GET /equipment/:id
(.:format)
{:controller=>“equipment”, :action=>“show”}
PUT /equipment/:id
(.:format)
{:controller=>“equipment”, :action=>“update”}
DELETE /equipment/:id
(.:format)
{:controller=>“equipment”, :action=>“destroy”}

I think you can easily create all this with

./script/generate scaffold Equipment

Is equipment a resource ?And also note after this the controller name.It
is plural

Sijo

I already have the controller, model and views. The
“new_equipment_path” generates a URL when presenting the view.
However, going to the /equipment/new URL (generated by the helper)
generates the error.

Rails pluralizes “Equipment” to “Equipment.” I picked that up from
researching the problem on this group. A guy had “equipments” and it
created a problem. He fixed that, but not the other problem (that
seems to be afflicting me). Or, rather, he fixed the problem but did
not post his solution.

The error message is spot on (except that is says “you may…”) as you
have problems with your routes. Try running “script/generate scaffold
Machine name:string” and the follow-on “rake db:migrate” and “rake
routes”. Look at the difference between the routes generated for
Equipment/Equipment and Machine/Machines.

With a heavy personal application of bsat (blood sweat and tears) you
can work around Rail’s expectation for distinct tense forms but you
won’t be happy.

That’s life in a syntactic sugar bowl…

I created a new project to test your point. The following are the
routes generated. In the case of machine, I have no problem with
“machines/new”, but “equipment/new” provides the exact-same error as
before. So, the route generated by Rails creates ambiguity without my
doing anything special.

map.resources :machines
map.resources :equipment

Your snide comment about BSAT is ignorant of the effort I’ve put into
trying to solve this problem. I’ve been professionally programming for
well over a decade, and typically resort to the hostility of forums
only after I can’t solve the problem through intense research. You
assume I’m the sort who runs to a forum first, not last.

Okay, that works in a separate project (the one where I follow Rick’s
suggestion). When I put in the inflector after I created the
scaffold, the routes weren’t satisfied.

I had to script/destroy “Equipment”, change the inflector, then script/
generate “Equipment” to get everything to sort itself out. Just
changing the inflector (and restarting the server) appears to be
insufficient.

Thanks for your patience, Sijo.

Hi
You can do like following

edit config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular ‘equipment’, ‘equipments’
end

Now as I said before
./script/generate scaffold Equipment

       That the solution. This is because rails takes plural of 

equipment as equipment And what did above is to override that
To test it from console do ‘equipment’.pluralize before and after
this and watch change

Sijo

Ben W. wrote:
[…]

Your snide comment about BSAT is ignorant of the effort I’ve put into
trying to solve this problem.

I didn’t read Rick’s comment as snide or hostile at all. I hope he will
explain his intentions, but I think he was simply trying to say that you
may be trying to do something that’s somewhat difficult. I do not
believe he was putting you down or implying that you hadn’t made
appropriate effort.

I’ve been professionally programming for
well over a decade, and typically resort to the hostility of forums
only after I can’t solve the problem through intense research.

Hostility? Have you actually read this list much? People here tend to
be quite friendly (with notable exceptions…).

You
assume I’m the sort who runs to a forum first, not last.

Again, I don’t believe Rick assumed anything of the kind. Rick, would
you care to clarify?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Ben,

I really didn’t intend any criticism of your efforts to make this work
and I apologize for any offense I gave.

What I have found to be true is that Rails has a fairly large
assumptions made about the form of your (that’s all of us, not just
you) code.

Two that immediately jump to mind are the singular/plural distinction
and the reuse of reserved words. The first you are now aware of, try
adding a model field like “type:string” and see what happens when you
assign to it for a demo of the second.

The authors of Rails have made real efforts to document assumptions
and related dependancies but the documentation is not always handy and
work arounds tend to get rediscovered. This is from my own
experience.

So here is my suggestion.

Do not, without a really good reason, use a Model name that doesn’t
have distinct singular/plural forms.

If you must use “equipment”, you will need to invent a singular or
plural form that is distinct and add it to your application’s “config/
initializers/inflections.rb” file. This file actually exists to cover
cases of pluralization that exist but are not included in the Rails
source but you can use it cover your situation as well.

There are two problems with this approach.

The first is admittedly a nit. You (and anyone else who needs to
maintain your code) will forever see what appears to be a typographic
error and, sooner or later, someone will make a “correction”.

The second is more than a nit. Since we very seldom touch the
inflections.rb file, the fact that this is the magic that makes
“equipment” work will be forgotten long before you do your taxonomy
project on “moose” variants.

I really hope this is helpful.

Rick

On Jul 25, 4:57 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-

I ran into this same problem (with ‘species’ rather than ‘equipment’
but it’s the same issue) and like others in this thread, I misread the
problem:

the problem is not a routes problem, it’s a scaffolding problem (the
problem is actually within the body of the generated scaffold erb
file).

In the scaffold, there are two problems in the generated
new.html.erb:

<% form_for(@MODELNAME) do |f| %>
and at the bottom
<%= link_to ‘Back’, species_path %>

each of these would generate errors

In the first case, the form_for just needs a bit of help. Use the
following:

<% form_for(@MODELNAME, :url=> {:action=>‘create’}) do |f| %>

In the second case, there is a specific route path_helper generated

<%= link_to ‘Back’, MODELNAME_index_path %>

models that have the same singluar and plural (whether genuinely
uncountable like equipment, or just because the two forms are the
same) have special name for the index path (because the plural isn’t
distinguished) and you need to use that:

equipment_index_path / species_index_path

So here is my suggestion.

Do not, without a really good reason, use a Model name that doesn’t
have distinct singular/plural forms.

So I would say, you SHOULD use whatever model name is appropriate
(excepting of course ruby/rails reserved words / key concepts) even if
there is no plural distinction, but you just need to adjust the
scaffold as above (and similarly elsewhere).

This should I think be fixed in rails, and apparently there’s no
ticket for it (at least I couldn’t find one), so I created a new
ticket:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3095-generated-scaffold-for-model-with-same-plural-as-singular-gives-errors

all the best

Tim