Title: Creating Controllers in ROR for MYSQL tables
Tags: mysql;ruby-on-rails
Question: I have created a new MySQL DB app through ruby console giving below command

```rails new -demo -d mysql
```

Then I created 1 table through MySQL editor. In Ruby Console I started rails server and its working fine (checked localhost:3000). Now I am unable to create controller class for this table. I tried many commands given on net but nothing seems to be working. 

From Ruby command console I switched to rails console giving below command

```rails console
```

Then I entered below command to create controller class which in turn returned nil

```irb(main):003:0&gt; class CategoryController < ApplicationController
irb(main):004:1&gt; def index
irb(main):005:2&gt; end
irb(main):006:1&gt; def show
irb(main):007:2&gt; end
irb(main):008:1&gt; end
=&gt; nil
```

But no such class got created in app/controller folder of my application. 

I read couple of tutorials and it was referred that controller classes gets automatically created in rails. I tried those too but they didn't run.

I am not sure if I am missing something. Could someone please help to guide further steps. I am using ROR only on server side. My Android app will be using this DB.

It will be really helpful if somebody can provide relevant Beginner tutorial or sample examples using ROR for server side coding with MySQL.

Thanks.

Comment: What book or site are you learning from? I would suggest working through the [Rails Tutorial](http://ruby.railstutorial.org) which is a great help to a newcomer to Rails.

Comment: Thanks Bert for link.

Here is the accepted answer: The Rails console is used to test code at runtime, not to generate code which is actually stored in files to be used again. The correct way to generate a controller is via the ```rails generate controller``` command from your system's command line (not from the Rails console or ```irb```):

This will create your ```CategoryController``` file with two actions, ```index, show```. You may omit those actions or add additional actions.

```rails generate controller CategoryController index show
```

This will result in output similar to what's below, assuming all your gem dependencies are correctly met.

```  create  app/controllers/category_controller_controller.rb
   route  get "category_controller/show"
   route  get "category_controller/index"
  invoke  erb
  create    app/views/category_controller
  create    app/views/category_controller/index.html.erb
  create    app/views/category_controller/show.html.erb
  invoke  test_unit
  create    test/controllers/category_controller_controller_test.rb
  invoke  helper
  create    app/helpers/category_controller_helper.rb
  invoke    test_unit
  create      test/helpers/category_controller_helper_test.rb
  invoke  assets
  invoke    js
  create      app/assets/javascripts/category_controller.js
  invoke    scss
  create      app/assets/stylesheets/category_controller.css.scss
```

Comment for this answer: Thanks a ton. I struggled for almost 5-6 hours before posting here. I guess it worked now. Ran the command and got o/p. Thanks again.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:08/04/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<mysql><ruby-on-rails>', 'Title': 'Creating Controllers in ROR for MYSQL tables', 'ViewCount': 213, 'id': 18043199, 'user_AboutMe': '', 'user_AccountId': 3047216.0, 'user_DisplayName': 'Gaurav', 'user_Reputation': 525.0, 'user_Views': 139.0, 'user_id': 2582509.0}}