I wanted to create the MVC template for the operators in my Rails application.
I used the scaffold in order to generate the template:
C:\learn\Ruby\ror\operators>rails generate scaffold Operator name:string title:s
tring age:integer birthDate:date
The scaffold routine create the following artifacts:
invoke active_record
create db/migrate/20130616075217_create_operators.rb
create app/models/operator.rb
invoke test_unit
create test/unit/operator_test.rb
create test/fixtures/operators.yml
invoke resource_route
route resources :operators
invoke scaffold_controller
create app/controllers/operators_controller.rb
invoke erb
create app/views/operators
create app/views/operators/index.html.erb
create app/views/operators/edit.html.erb
create app/views/operators/show.html.erb
create app/views/operators/new.html.erb
create app/views/operators/_form.html.erb
invoke test_unit
create test/functional/operators_controller_test.rb
invoke helper
create app/helpers/operators_helper.rb
invoke test_unit
create test/unit/helpers/operators_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/operators.js.coffee
invoke scss
create app/assets/stylesheets/operators.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss
The operator model contains 4 members
The generated DB migration code :found in C:\learn\Ruby\ror\operators\db\migrate\20130616075217_create_operators.rb
1: class CreateOperators < ActiveRecord::Migration
2: def change
3: create_table :operators do |t|
4: t.string :name5: t.string :title6: t.integer :age7: t.date :birthDate8:9: t.timestamps10: end
11: end
12: end
13:
Execute the migration
C:\learn\Ruby\ror\operators>rake db:migrate
The Result in the mySQL DB
Changing the main controller to add link to the operator controller :
<h1>Operators </h1>
<p>Operator: <%= @theOperator.Name %></p>
<%= link_to "Operators", operators_path %>
Resources
http://overooped.com/post/100354794/ruby-script-generate-scaffold-typeshttp://guides.rubyonrails.org/getting_started.html
אין תגובות:
הוסף רשומת תגובה