undefined method `model_name' for NilClass:Class in a form_for

Hi! I know that there are other topics about this issue, I read them and I'm always blocked. Here is the error message:

undefined method `model_name' for NilClass:Class

Extracted source (around line #30):

27: 28: <h2>Add Translation</h2> 29: 30: <%= form_for @new_trad do |f| %> 31: Locale: <%= f.text_field :locale %> 32: Key : <%= f.text_field :key %> 33: Value : <%= f.text_field :value %>

The new method in TranslationsController:

  def new     @new_trad = Translations.new   end

Tell me if other informations are needed. Thanks in advance!

ps: Sorry for my bad english :slight_smile:

undefined method `model_name' for NilClass:Class

30: <%= form_for @new_trad do |f| %>

This means that the @new_trad object is probably nil.

def new @new_trad = Translations.new end

Just a guess, but you might want: @new_trad = Translation.new

If that's not it, I'd recommend checking out the guides on debugging and put a breakpoint in the view.

Michael Pavling wrote in post #1001495:

Just a guess, but you might want: @new_trad = Translation.new

No, it's Translations and I forgot to tell that it's not an ActiveRecord model.

Right... so the form_for stuff won't work then, unless you add all the methods it needs that a "normal" model would inherit from AR::Base (or probably won't work at all - use a form_tag instead...)

Michael Pavling wrote in post #1001516:

Right... so the form_for stuff won't work then, unless you add all the methods it needs that a "normal" model would inherit from AR::Base (or probably won't work at all - use a form_tag instead...)

Thanks you, i tried with form_tag and it works.