I looked around on Stack Overflow and Agile Development with Rails but couldn't find anything that answered all the parts of this I need.
I just generated a Cow model in rails. Apparently, Rails uses an antiquated plural of cow ("kine"), so when I created that model, it built a Kine migration:
class CreateKine < ActiveRecord::Migration
def change
create_table :kine do |t|
t.string :name
t.string :farm
t.string :breed
t.timestamps
end
end
end
I know I could go into the model's .rb file and set_table_name back to cow, but I'm worried about associated controllers. If I create a Cows controller, will it not sync up?
How do I get everything to be Cow/Cows? Thanks. This is one of my first apps, and I'm already way confused by managing controller-model associations, so this inflection issue doesn't help.
Create an inflection here is an example:
config>initializers>inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'cow', 'cows'
end
Try to rename the table:
class RenameKineToCows< ActiveRecord:Migration def up rename_table :kine, :cows end def down rename_table :cows, :kine end end
Rename your app/models/kine.rb to cow.rb and edit the file
class Cow < ActiveRecord::Base self.table_name = 'Cow' end
Rename your app/controllers/kine_controller.rb to cows_controller.rb and edit the file
class KineController < ApplicationController
to
class CowsController < ApplicationController
and edit config/routes.rb
resources :kine
to
resources :cows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With