2016年10月1日 星期六

Rails 的命名慣例

1, migration 的 tables名,複數
class CreatePostTable < ActiveRecord::Migration
  def change
    create_table :posts do |t|
    end
  end
end
2, controller名,複數
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
end
3, models名,單數
# app/models/post.rb
class Post < ActiveRecord::Base
end
4, views名,資料夾是複數
# app/views/posts/index.html.erb

沒有留言:

張貼留言