I’ve found multiple solutions to this problem, but none of them seem to work for me. In my messages/index.html.erb, I’ve put:
<%= form_for(@message, :remote => true) do |f| %>
<%= f.text_field :content %>
<%= f.submit "Send" %>
<% end %>
and in my MessagesController:
def index
@message = Message.new
@messages = Message.all
end
and in my routes.rb:
get "/messages/index"
but for some reason I’m getting the error:
NoMethodError in Messages#index
undefined method `messages_path' for #<#<Class:0x0000010207d7c8>:0x0000010205c6b8>
Extracted source (around line #5):
2: <%= render @messages %>
3: </ul>
4:
5: <%= form_for(@message, :remote => true) do |f| %>
6: <%= f.text_field :content %>
7: <%= f.submit "Send" %>
8: <% end %>
How can I fix this?
form_for, the way you are using it, expects your routes to be set as a resource to a controller.
You should have in your routes
This will provide you will all the restful URL’s
http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions