Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
788d9238
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
788d9238
编写于
4月 11, 2010
作者:
A
Andrew White
提交者:
José Valim
4月 12, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generate module file for namespaced models [#4230 state:resolved]
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
b9b9f9ee
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
0 deletion
+33
-0
activerecord/lib/rails/generators/active_record/model/model_generator.rb
...b/rails/generators/active_record/model/model_generator.rb
+5
-0
activerecord/lib/rails/generators/active_record/model/templates/module.rb
.../rails/generators/active_record/model/templates/module.rb
+5
-0
railties/lib/rails/generators/rails/model/USAGE
railties/lib/rails/generators/rails/model/USAGE
+15
-0
railties/test/generators/model_generator_test.rb
railties/test/generators/model_generator_test.rb
+8
-0
未找到文件。
activerecord/lib/rails/generators/active_record/model/model_generator.rb
浏览文件 @
788d9238
...
...
@@ -20,6 +20,11 @@ def create_model_file
template
'model.rb'
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
.rb"
)
end
def
create_module_file
return
if
class_path
.
empty?
template
'module.rb'
,
File
.
join
(
'app/models'
,
"
#{
class_path
.
join
(
'/'
)
}
.rb"
)
end
hook_for
:test_framework
protected
...
...
activerecord/lib/rails/generators/active_record/model/templates/module.rb
0 → 100644
浏览文件 @
788d9238
module
<
%= class_path.map(&:camelize).join('::') %>
def self.table_name_prefix
'<%=
class_path
.
join
(
'_'
)
%>
_
'
end
end
railties/lib/rails/generators/rails/model/USAGE
浏览文件 @
788d9238
...
...
@@ -15,6 +15,10 @@ Description:
Finally, if --parent option is given, it's used as superclass of the
created model. This allows you create Single Table Inheritance models.
If you pass a namespaced model name (e.g. admin/account or Admin::Account)
then the generator will create a module with a table_name_prefix method
to prefix the model's table name with the module name (e.g. admin_account)
Examples:
`rails generate model account`
...
...
@@ -28,3 +32,14 @@ Examples:
`rails generate model post title:string body:text published:boolean`
Creates a Post model with a string title, text body, and published flag.
`rails generate model admin/account`
For ActiveRecord and TestUnit it creates:
Module: app/models/admin.rb
Model: app/models/admin/account.rb
Test: test/unit/admin/account_test.rb
Fixtures: test/fixtures/admin_accounts.yml
Migration: db/migrate/XXX_add_admin_accounts.rb
railties/test/generators/model_generator_test.rb
浏览文件 @
788d9238
...
...
@@ -27,6 +27,14 @@ def test_model_with_underscored_parent_option
assert_file
"app/models/account.rb"
,
/class Account < Admin::Account/
end
def
test_model_with_namespace
run_generator
[
"admin/account"
]
assert_file
"app/models/admin.rb"
,
/module Admin/
assert_file
"app/models/admin.rb"
,
/def self\.table_name_prefix/
assert_file
"app/models/admin.rb"
,
/'admin_'/
assert_file
"app/models/admin/account.rb"
,
/class Admin::Account < ActiveRecord::Base/
end
def
test_migration
run_generator
assert_migration
"db/migrate/create_accounts.rb"
,
/class CreateAccounts < ActiveRecord::Migration/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录