我对 ruby 完全陌生,但我知道如何创建数据库。我做了这个
rails generate scaffold MYTABLENAME
在 db/migrate 我编辑了文件,所以它有我的列等。
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :username
t.string :password
t.string :email
t.timestamps
end
end
end
这是正确的吧?
现在我得到了这个输出:
invoke active_record
create db/migrate/20130325134909_create_posts.rb
create app/models/post.rb
invoke test_unit
create test/unit/post_test.rb
create test/fixtures/posts.yml
invoke resource_route
route resources :posts
invoke scaffold_controller
create app/controllers/posts_controller.rb
invoke erb
create app/views/posts
create app/views/posts/index.html.erb
create app/views/posts/edit.html.erb
create app/views/posts/show.html.erb
create app/views/posts/new.html.erb
create app/views/posts/_form.html.erb
invoke test_unit
create test/functional/posts_controller_test.rb
invoke helper
create app/helpers/posts_helper.rb
invoke test_unit
create test/unit/helpers/posts_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/posts.js.coffee
invoke scss
create app/assets/stylesheets/posts.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss
invoke active_record
create db/migrate/20130325134909_create_posts.rb
create app/models/post.rb
invoke test_unit
create test/unit/post_test.rb
create test/fixtures/posts.yml
invoke resource_route
route resources :posts
invoke scaffold_controller
create app/controllers/posts_controller.rb
invoke erb
create app/views/posts
create app/views/posts/index.html.erb
create app/views/posts/edit.html.erb
create app/views/posts/show.html.erb
create app/views/posts/new.html.erb
create app/views/posts/_form.html.erb
invoke test_unit
create test/functional/posts_controller_test.rb
invoke helper
create app/helpers/posts_helper.rb
invoke test_unit
create test/unit/helpers/posts_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/posts.js.coffee
invoke scss
create app/assets/stylesheets/posts.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss
听起来也不错。但是为什么会自动插入
app/views/posts/index.html.erb
app/views/posts/edit.html.erb
app/views/posts/show.html.erb
app/views/posts/new.html.erb
app/views/posts/_form.html.erb
等等?它是标准的,如果是的话 - 为什么?请解释。
另一个问题是:在我的家庭控制器(作为标准../home/index)中,我试图在我的新数据库中创建一个用户,但它告诉我未初始化的常量 HomeController::Users - 为什么?
这是我的代码:
class HomeController < ApplicationController
def index
#@users = User.all
o = Users.new
o.username = "Jesper"
o.save
end
end