Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
80cd1637
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,发现更多精彩内容 >>
提交
80cd1637
编写于
7月 01, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added scaffold views to scaffold controller.
上级
9541977e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
147 addition
and
4 deletion
+147
-4
railties/lib/generators/erb/scaffold/scaffold_generator.rb
railties/lib/generators/erb/scaffold/scaffold_generator.rb
+42
-0
railties/lib/generators/erb/scaffold/templates/edit.html.erb
railties/lib/generators/erb/scaffold/templates/edit.html.erb
+18
-0
railties/lib/generators/erb/scaffold/templates/index.html.erb
...ties/lib/generators/erb/scaffold/templates/index.html.erb
+24
-0
railties/lib/generators/erb/scaffold/templates/layout.html.erb
...ies/lib/generators/erb/scaffold/templates/layout.html.erb
+17
-0
railties/lib/generators/erb/scaffold/templates/new.html.erb
railties/lib/generators/erb/scaffold/templates/new.html.erb
+17
-0
railties/lib/generators/erb/scaffold/templates/show.html.erb
railties/lib/generators/erb/scaffold/templates/show.html.erb
+10
-0
railties/lib/generators/generated_attribute.rb
railties/lib/generators/generated_attribute.rb
+4
-0
railties/lib/generators/named_base.rb
railties/lib/generators/named_base.rb
+3
-2
railties/lib/generators/rails/scaffold/scaffold_generator.rb
railties/lib/generators/rails/scaffold/scaffold_generator.rb
+2
-0
railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
...ails/scaffold_controller/scaffold_controller_generator.rb
+8
-2
railties/lib/generators/rails/scaffold_controller/templates/controller.rb
...erators/rails/scaffold_controller/templates/controller.rb
+2
-0
未找到文件。
railties/lib/generators/erb/scaffold/scaffold_generator.rb
0 → 100644
浏览文件 @
80cd1637
require
'generators/erb'
module
Erb
module
Generators
class
ScaffoldGenerator
<
Base
include
Rails
::
Generators
::
ControllerNamedBase
argument
:attributes
,
:type
=>
:hash
,
:default
=>
{},
:banner
=>
"field:type field:type"
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to skip index action"
# TODO Spec me
def
copy_index_file
return
if
options
[
:singleton
]
copy_view
:index
end
def
copy_edit_file
copy_view
:edit
end
def
copy_show_file
copy_view
:show
end
def
copy_new_file
copy_view
:new
end
# TODO invoke_if?
def
copy_layout_file
template
"layout.html.erb"
,
File
.
join
(
"app"
,
"views"
,
"layouts"
,
controller_class_path
,
"
#{
controller_file_name
}
.html.erb"
)
end
protected
def
copy_view
(
view
)
template
"
#{
view
}
.html.erb"
,
File
.
join
(
"app"
,
"views"
,
controller_file_path
,
"
#{
view
}
.html.erb"
)
end
end
end
end
railties/lib/generators/erb/scaffold/templates/edit.html.erb
0 → 100644
浏览文件 @
80cd1637
<h1>
Editing
<%=
singular_name
%>
</h1>
<%%
form_for
(
@
<
%= singular_name
%>
) do |f| %>
<%%
=
f
.
error_messages
%>
<%
for
attribute
in
attributes
-%>
<p>
<%%
=
f
.
label
:<
%=
attribute
.
name
%>
%>
<br
/>
<%%
=
f
.
<
%=
attribute
.
field_type
%>
:
<%=
attribute
.
name
%>
%>
</p>
<%
end
-%>
<p>
<%%
=
f
.
submit
'Update'
%>
</p>
<%%
end
%>
<%%
=
link_to
'Show'
,
@
<
%= singular_name
%>
%> |
<%%
=
link_to
'Back'
,
<
%= plural_name
%>
_path %>
\ No newline at end of file
railties/lib/generators/erb/scaffold/templates/index.html.erb
0 → 100644
浏览文件 @
80cd1637
<h1>
Listing
<%=
plural_name
%>
</h1>
<table>
<tr>
<%
for
attribute
in
attributes
-%>
<th>
<%=
attribute
.
human_name
%>
</th>
<%
end
-%>
</tr>
<%%
@
<
%= plural_name
%>
.each do |
<%=
singular_name
%>
| %>
<tr>
<%
for attribute in attributes
-%>
<td>
<%%
=
h
<
%= singular_name
%>
.
<%=
attribute.name
%>
%>
</td>
<%
end
-%>
<td>
<%%
=
link_to
'Show'
,
<
%= singular_name
%>
%>
</td>
<td>
<%%
=
link_to
'Edit'
,
edit_
<
%= singular_name
%>
_path(
<%=
singular_name
%>
) %>
</td>
<td>
<%%
=
link_to
'Destroy'
,
<
%= singular_name
%>
, :confirm => 'Are you sure?', :method => :delete %>
</td>
</tr>
<%%
end
%>
</table>
<br
/>
<%%
=
link_to
'
New
<
%= singular_name
%>
', new_
<%=
singular_name
%>
_path %>
railties/lib/generators/erb/scaffold/templates/layout.html.erb
0 → 100644
浏览文件 @
80cd1637
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xml:lang=
"en"
lang=
"en"
>
<head>
<meta
http-equiv=
"content-type"
content=
"text/html;charset=UTF-8"
/>
<title>
<%=
controller_class_name
%>
:
<%%
=
controller
.
action_name
%>
</title>
<%%
=
stylesheet_link_tag
'scaffold'
%>
</head>
<body>
<p
style=
"color: green"
>
<%%
=
flash
[
:notice
]
%>
</p>
<%%
=
yield
%>
</body>
</html>
railties/lib/generators/erb/scaffold/templates/new.html.erb
0 → 100644
浏览文件 @
80cd1637
<h1>
New
<%=
singular_name
%>
</h1>
<%%
form_for
(
@
<
%= singular_name
%>
) do |f| %>
<%%
=
f
.
error_messages
%>
<%
for
attribute
in
attributes
-%>
<p>
<%%
=
f
.
label
:<
%=
attribute
.
name
%>
%>
<br
/>
<%%
=
f
.
<
%=
attribute
.
field_type
%>
:
<%=
attribute
.
name
%>
%>
</p>
<%
end
-%>
<p>
<%%
=
f
.
submit
'Create'
%>
</p>
<%%
end
%>
<%%
=
link_to
'Back'
,
<
%= plural_name
%>
_path %>
\ No newline at end of file
railties/lib/generators/erb/scaffold/templates/show.html.erb
0 → 100644
浏览文件 @
80cd1637
<%
for
attribute
in
attributes
-%>
<p>
<b>
<%=
attribute
.
column
.
human_name
%>
:
</b>
<%%
=
h
@
<
%= singular_name
%>
.
<%=
attribute.name
%>
%>
</p>
<%
end
-%>
<%%
=
link_to
'Edit'
,
edit_
<
%= singular_name
%>
_path(@
<%=
singular_name
%>
) %> |
<%%
=
link_to
'Back'
,
<
%= plural_name
%>
_path %>
\ No newline at end of file
railties/lib/generators/generated_attribute.rb
浏览文件 @
80cd1637
...
...
@@ -35,6 +35,10 @@ def default
end
end
def
human_name
name
.
to_s
.
humanize
end
def
reference?
[
:references
,
:belongs_to
].
include?
(
self
.
type
)
end
...
...
railties/lib/generators/named_base.rb
浏览文件 @
80cd1637
...
...
@@ -96,7 +96,8 @@ def self.check_class_collision(options={})
#
module
ControllerNamedBase
def
self
.
included
(
base
)
#:nodoc:
base
.
send
:attr_reader
,
:controller_name
,
:controller_class_name
,
:controller_file_name
base
.
send
:attr_reader
,
:controller_name
,
:controller_class_name
,
:controller_file_name
,
:controller_class_path
,
:controller_file_path
end
# Set controller variables on initialization.
...
...
@@ -105,7 +106,7 @@ def initialize(*args)
super
@controller_name
=
name
.
pluralize
base_name
,
class_path
,
file_path
,
class_nesting
,
class_nesting_depth
=
extract_modules
(
@controller_name
)
base_name
,
@controller_class_path
,
@controller_
file_path
,
class_nesting
,
class_nesting_depth
=
extract_modules
(
@controller_name
)
class_name_without_nesting
,
@controller_file_name
,
controller_plural_name
=
inflect_names
(
base_name
)
@controller_class_name
=
if
class_nesting
.
empty?
...
...
railties/lib/generators/rails/scaffold/scaffold_generator.rb
浏览文件 @
80cd1637
...
...
@@ -7,6 +7,8 @@ class ScaffoldGenerator < ResourceGenerator #metagenerator
remove_hook_for
:actions
,
:resource_controller
hook_for
:scaffold_controller
,
:required
=>
true
# invoke_if stylesheets
end
end
end
railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
浏览文件 @
80cd1637
...
...
@@ -5,14 +5,19 @@ class ScaffoldControllerGenerator < NamedBase
check_class_collision
:suffix
=>
"Controller"
class_option
:orm
,
:desc
=>
"ORM to generate the controller for"
,
:banner
=>
"NAME"
,
:type
=>
:string
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to create a singleton controller"
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to create a singleton controller"
# TODO Spec me
def
create_controller_files
template
'controller.rb'
,
File
.
join
(
'app/controllers'
,
class_path
,
"
#{
file_name
}
_controller.rb"
)
end
hook_for
:template_engine
,
:test_framework
,
:as
=>
:scaffold
invoke_if
:helper
# Invoke the helper using the controller (pluralized) name.
#
invoke_if
:helper
do
|
base
,
invoked
|
base
.
invoke
invoked
,
[
base
.
controller_name
]
end
protected
...
...
@@ -23,6 +28,7 @@ def orm_class
def
orm_instance
@orm_instance
||=
@orm_class
.
new
(
file_name
)
end
end
end
end
railties/lib/generators/rails/scaffold_controller/templates/controller.rb
浏览文件 @
80cd1637
class
<
%= controller_class_name %>Controller < ApplicationController
<% unless options[:singleton] -%>
# GET /<%=
table_name
%>
# GET /<%= table_name %>
.
xml
def
index
...
...
@@ -9,6 +10,7 @@ def index
format.xml { render :xml =
>
@
<
%= table_name %> }
end
end
<% end -%>
# GET /<%=
table_name
%>/1
# GET /<%= table_name %>
/1.xml
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录