0

I have this model Oferta

class Oferta < ActiveRecord::Base
  belongs_to :entidade
  has_many :candidatos, :through => :interesses
  has_many :interesses, foreign_key: "oferta_id", dependent: :destroy

  validates :entidade_id, presence: true

  validates :titulo, :presence => { :message => "Título tem de ser preenchido" }, length: { maximum: 40, message: "Título muito extenso! Máximo 40 caracteres!" }
  validates :corpo, :presence => { :message => "Corpo tem de ser preenchido" }, length: { maximum: 150, message: "Corpo muito extenso! Máximo 150 caracteres!" }
  validates :tipo, inclusion: { in: %w(full_time part_time), message: "%{value} não é válido" }
  validates :salario, numericality: { only_integer: true }

i have resources :ofertas in the routes file.

And so far the routing is fine and it works. But in my view:

<% provide(:title,"Editar Oferta") %>
<h1>Editar Oferta</h1>
<div class="row">
  <div class="span6 offset3">
    <%= simple_form_for @oferta do |f| %>
      <%= render 'shared/error_messages' %>
      <%= f.input :titulo %>
      <%= f.input :corpo %>
      <%= f.input :data_inicio %>/<%= f.input :data_fim %>
      <%= f.input :atividade %>
      <%= f.select :tipo, ["full_time","part_time"], :label => "Tipo" %>
      <%= f.input :salario %>
      <%= f.select :ativa, ["true","false"], :label => "Atiar/Desativar"  %>
    <% end %>
  </div>
</div>

I get a undefined method 'ofertum_path' in the simple_form_for tag.....

my controller so far is this:

class OfertasController < ApplicationController
  def edit
    @oferta = Oferta.find(params[:id])
  end

I just dont get where the ofertum is coming from. Can someone help me?

João Cunha
  • 9,929
  • 4
  • 40
  • 61
  • What do you see if you `rake routes`? – j-dexx Aug 26 '14 at 09:57
  • the normal routes. everything is normal. I found an answer here. http://stackoverflow.com/questions/14740702/form-for-undefined-method-user-path but i dont quite understand it – João Cunha Aug 26 '14 at 09:58
  • resources :oferta instead of resources :ofertas can you try route something like this – Babasaheb Gosavi Aug 26 '14 at 10:00
  • tried it before. the controller stops working that way – João Cunha Aug 26 '14 at 10:02
  • 4
    @Lokuzt it's because rails will try and guess the controller by pluralizing the object so in this case `Oferta`. If I fire up console and pluralize Oferta I just get Oferta. You should be able to fix it through `config/initializers/inflections.rb` with something like `inflect.irregular 'oferta', 'ofertas'` – j-dexx Aug 26 '14 at 10:16
  • "Oferta".singularize returns "Ofertum". Why is your model named Oferta then? Btw. you should code in english. I argue the wrong singularization of your model confuses. Did you configured the inflection for "Oferta" correctly then? – Christian Rolle Aug 26 '14 at 12:44

0 Answers0