0

Well, i'm new to rails, but not new to the rails way and i've got an error that i dont know how to fix it.

I've created the controller and than the view.

Controller:

class ReclamacoesController < ApplicationController

    def new
       @reclamacao = Reclamacao.new
    end
end

and than, the view under Views>controllerName>new.html.erb.

<%= form_for @reclamacao do |f| %>
    <%= f.text_field  :titulo %>
<% end %>

The model Reclamacao exist.

I've created the resource routes for it too.

resources :reclamacoes

So, when i access /reclamacoes/new an exception is thrown.

NoMethodError in Reclamacoes#new 
undefined method `reclamacaos_path' for #<#<Class:0x00000001fc0660>:0x00000001fba850>

Extracted source (around line #1):
<%= form_for @reclamacao do |f| %>
    <%= f.text_field  :titulo %>
<% end %>

Rails.root: /home/ubuntu/workspace/aqueleprojetoprivate/medicos
Application Trace | Framework Trace | Full Trace

app/views/reclamacoes/new.html.erb:1:in `_app_views_reclamacoes_new_html_erb___3194888715597102324_16164860'

the routes:

     reclamacoes GET    /reclamacoes(.:format)          reclamacoes#index
                 POST   /reclamacoes(.:format)          reclamacoes#create
   new_reclamaco GET    /reclamacoes/new(.:format)      reclamacoes#new
  edit_reclamaco GET    /reclamacoes/:id/edit(.:format) reclamacoes#edit
       reclamaco GET    /reclamacoes/:id(.:format)      reclamacoes#show
                 PATCH  /reclamacoes/:id(.:format)      reclamacoes#update
                 PUT    /reclamacoes/:id(.:format)      reclamacoes#update
                 DELETE /reclamacoes/:id(.:format)      reclamacoes#destroy

What is wrong?

PlayMa256
  • 6,603
  • 2
  • 34
  • 54

2 Answers2

2

Rails is trying to automatically guess plurals. The problem is that your resource is reclamacao which Rails is turning into reclamacaos plural. But you have named it as reclamacoes

I suggest either changing names or instruct Rails to use better plurals. Here's a relevant article: How do I override rails naming conventions?

Community
  • 1
  • 1
Zepplock
  • 28,655
  • 4
  • 35
  • 50
1

Take a look at the output from rake routes. You will notice a spelling error

reclamacoes    GET    /reclamacoes(.:format)          reclamacoes#index
               POST   /reclamacoes(.:format)          reclamacoes#create
new_reclamaco  GET    /reclamacoes/new(.:format)      reclamacoes#new
edit_reclamaco GET    /reclamacoes/:id/edit(.:format) reclamacoes#edit
reclamaco      GET    /reclamacoes/:id(.:format)      reclamacoes#show
               PATCH  /reclamacoes/:id(.:format)      reclamacoes#update
               PUT    /reclamacoes/:id(.:format)      reclamacoes#update
               DELETE /reclamacoes/:id(.:format)      reclamacoes#destroy

Based on the above output, the correct path name is reclamacoes path.

Rails emphasizes Convention over Configuration, and you have different spellings in your models, views and controllers.

Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87