Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:06:15+00:00 2026-06-09T15:06:15+00:00

I started a Rails app and everything works fine. But now, I would like

  • 0

I started a Rails app and everything works fine. But now, I would like to rename a controller and the associated model:

I wanted to change the Corps controller to Stores and the same (without final s) for the model.

Looking on google, people suggested to destroy and then generate again the controller and model. The problem is that it will erase the actual code of each files!

What’s the solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:06:17+00:00Added an answer on June 9, 2026 at 3:06 pm

    Here is what I would do:

    Create a migration to change the table name (database level). I assume your old table is called corps. The migration content will be:

    class RenameCorpsToStores < ActiveRecord::Migration
      def change
        rename_table :corps, :stores
      end
    end
    

    Change your model file name, your model class definition and the model associations:

    • File rename: corp.rb -> store.rb
    • Code of store.rb: Change class Corp for class Store
    • Rename all the model associations like has_many :corps -> has_many :stores

    Change your controller file name and your controller class definition:

    • File rename: corps_controller.rb -> stores_controller.rb
    • Code of stores_controller.rb: Change class CorpsController for class StoresController

    Rename views folders. From corps to stores.

    Make the necessary changes in paths in the config/routes.rb file, like resources :corps -> resources :stores, and make sure all the references in the code change from corps to stores (corps_path, …)

    Remember to run the migration 🙂

    If previous is not possible, try to delete the db/schema.rb and execute:

     $ rake db:drop db:create db:migrate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everything was working fine in Rails 3.0.14, but after changing gem 'rails', '3.0.14' to
I started developing my Rails app for Windows (I know, bad idea). I now
Basically I would like to access the same Rails app in production or environment
I had started the Rails app yesterday and got everything working. Then today I
In a Rails app I started using sunspot => https://github.com/sunspot/sunspot/blob/master/README.md Everything went OK until
I started writing functional tests for my rails app today. I use the RESTful
SOLUTION FOUND: See comment Building a new rails 3.1 app. Started with a basic
I have started developing a new Rails app on my server using RVM, Rails
I have a jruby rails app and I've just started using bundler for gem
I got started by following this awesome tutorial , but wanted to do the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.