user1616238
user1616238

Reputation:

Undefined method 'model_name' in index.html.erb

I have a Dashboard controller and in the index method i have @message = Message.new( Message is my model )...In my index.html.erb i have a form

<%= form_for @message do |f| %>
    <%= f.text_field :message %><br>
    <%= f.submit "Send" %>
<% end %>

and i get an error at first line of the form "undefined method `messages_path'"...

I don't have a new method in my controller

Pls help

Upvotes: 1

Views: 253

Answers (2)

Taimoor Changaiz
Taimoor Changaiz

Reputation: 10684

that error occurs when you did not specified respective routes in routes.rb file so just add
resources :messages

or if you want explicit route for some certain method add that in route file

Upvotes: 1

Jim Deville
Jim Deville

Reputation: 10662

Do you have a resources :messages route in config/routes.rb? The error is happening when Rails tries to create the form's submission route from the class of the argument to form_for

Upvotes: 2

Related Questions