[ruby] Uninitialized Constant MessagesController

I'm building a simple chat app based on this rails cast. I'm following along fine, but when I go to localhost, I get an error "uninitialized constant MessagesController::Message". This is generally a simple fix, but I have spent over an hour looking for the fix and I cannot see it. Here is my code;

messages_controller

class MessagesController < ApplicationController      def index         @messages = Message.all     end      def create         @message = Message.create!(params[:message])         PrivatePub.publish_to("/messages/new", "alert('#{@message.content}');")     end  end 

model (message.rb)

class Message end 

index & message form (index.html.erb);

<h1>Hack Chat</h1>  <ul id="chat">     <%= render @messages %> </ul>  <%= form_for Message.new, remote: true do |f| %>     <%= f.text_field :content %>     <%= f.submit "Send" %> <% end %>  <%= subscribe_to "/messages/new" %> 

routes.rb;

Hackchat::Application.routes.draw do     root to: 'messages#index'     resources :messages end 

gemfile;

source 'https://rubygems.org'  gem 'rails', '4.0.0' gem 'sqlite3'  group :assets do      gem 'sass-rails', '~> 4.0.0'     gem 'uglifier', '>= 1.3.0'     gem 'coffee-rails', '~> 4.0.0' end  gem 'jquery-rails' gem 'private_pub' gem "thin", "~> 1.6.1" 

I have checked every possible thing I could think of as to why I would be getting this error, and I really do not know why. Any help would be much appreciated.

Also, for using private pub, do I have to run two terminal windows, one running rails server, and the other running faye?

This question is related to ruby ruby-on-rails-4

The answer is


Your model is @Messages, change it to @message.

To change it like you should use migration:

def change   rename_table :old_table_name, :new_table_name end 

Of course do not create that file by hand but use rails generator:

rails g migration ChangeMessagesToMessage 

That will generate new file with proper timestamp in name in 'db dir. Then run:

rake db:migrate 

And your app should be fine since then.