2014-11-28 4 views
2

Я создал моделирование данных и импортировал файл sql и сгенерировал схему для всех моих моделей, как показано ниже. Теперь я хочу сгенерировать модели для всех моих таблиц в MySQl без файлов миграции.Rails Создать модель без файлов миграции

Кроме того, у меня есть два импоптома и вы хотите использовать ту же модель для всех контроллеров с разными именами.

# Create a new Rails Project 
rails new <project-name> -d mysql 

# Run Bundler 
bundle install 

# Database Initiation 
rake db:create 

# Dump SQL file into MySQL 
mysql -u hmv -p <database-name> < <database-file> 

# Generate SQL Schema from the MySQL tables 
rake db:schema:dump 

# Creating a Git Repo for Versioning and Collaboration 
git init 
git remote add origin https://<Username>:<Password>@bitbucket.org/harshamv/<Project-Name>.git 
git add . 
git commit -m 'Initial commit' 
git push -u origin master 

# Create the Initial Migration File 
rails generate migration initial_schema_dump 

# Copy the Content from the Schema file to the migration file and run the following command 
rake db:migrate 

ответ

5

Вы можете использовать опцию --skip_migration

rails g model MyModel --skip_migration 
    invoke  active_record 
    create  app/models/my_model.rb 
    invoke  test_unit 
    create  test/models/my_model_test.rb 
    create  test/fixtures/my_models.yml 
+0

есть способ мессы генерировать это из всех таблиц из схемы? –

+0

Не то, чтобы я знал. Прокомментируйте здесь, если я натолкнулся на что-нибудь. – Santhosh

+0

спасибо большое. некоторые ожидания, когда вы переходите от других фреймворков: P –

Смежные вопросы