Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e1dd2846
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,体验更适合开发者的 AI 搜索 >>
提交
e1dd2846
编写于
10月 06, 2012
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More Ruby 1.9 hash syntax.
上级
e1e4b1d1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
52 deletion
+47
-52
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+47
-52
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
e1dd2846
...
...
@@ -207,7 +207,7 @@ module FormHelper
# if the object's class is +Post+. However, this can be overwritten using
# the <tt>:as</tt> option, e.g. -
#
# <%= form_for(@person,
:as =>
:client) do |f| %>
# <%= form_for(@person,
as:
:client) do |f| %>
# ...
# <% end %>
#
...
...
@@ -242,7 +242,7 @@ module FormHelper
#
# is then equivalent to something like:
#
# <%= form_for @post,
:as => :post, :url => post_path(@post), :method => :put, :html => { :class => "edit_post", :id =>
"edit_post_45" } do |f| %>
# <%= form_for @post,
as: :post, url: post_path(@post), method: :put, html: { class: "edit_post", id:
"edit_post_45" } do |f| %>
# ...
# <% end %>
#
...
...
@@ -254,19 +254,19 @@ module FormHelper
#
# is equivalent to something like:
#
# <%= form_for @post,
:as => :post, :url => posts_path, :html => { :class => "new_post", :id =>
"new_post" } do |f| %>
# <%= form_for @post,
as: :post, url: posts_path, html: { class: "new_post", id:
"new_post" } do |f| %>
# ...
# <% end %>
#
# However you can still overwrite individual conventions, such as:
#
# <%= form_for(@post,
:url =>
super_posts_path) do |f| %>
# <%= form_for(@post,
url:
super_posts_path) do |f| %>
# ...
# <% end %>
#
# You can also set the answer format, like this:
#
# <%= form_for(@post,
:format =>
:json) do |f| %>
# <%= form_for(@post,
format:
:json) do |f| %>
# ...
# <% end %>
#
...
...
@@ -290,7 +290,7 @@ module FormHelper
#
# You can force the form to use the full array of HTTP verbs by setting
#
#
:method =>
(:get|:post|:patch|:put|:delete)
#
method:
(:get|:post|:patch|:put|:delete)
#
# in the options hash. If the verb is not GET or POST, which are natively
# supported by HTML forms, the form will be set to POST and a hidden input
...
...
@@ -300,7 +300,7 @@ module FormHelper
#
# Specifying:
#
#
:remote =>
true
#
remote:
true
#
# in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its
# behavior. The expected default behavior is an XMLHttpRequest in the background instead of the regular
...
...
@@ -310,7 +310,7 @@ module FormHelper
#
# Example:
#
# <%= form_for(@post,
:remote =>
true) do |f| %>
# <%= form_for(@post,
remote:
true) do |f| %>
# ...
# <% end %>
#
...
...
@@ -354,7 +354,7 @@ module FormHelper
# Example:
#
# <%= form_for(@post) do |f| %>
# <%= f.fields_for(:comments,
:include_id =>
false) do |cf| %>
# <%= f.fields_for(:comments,
include_id:
false) do |cf| %>
# ...
# <% end %>
# <% end %>
...
...
@@ -366,7 +366,7 @@ module FormHelper
# custom builder. For example, let's say you made a helper to
# automatically add labels to form inputs.
#
# <%= form_for @person,
:url => { :action => "create" }, :builder =>
LabellingFormBuilder do |f| %>
# <%= form_for @person,
url: { action: "create" }, builder:
LabellingFormBuilder do |f| %>
# <%= f.text_field :first_name %>
# <%= f.text_field :last_name %>
# <%= f.text_area :biography %>
...
...
@@ -390,7 +390,7 @@ module FormHelper
#
# def labelled_form_for(record_or_name_or_array, *args, &proc)
# options = args.extract_options!
# form_for(record_or_name_or_array, *(args << options.merge(
:builder =>
LabellingFormBuilder)), &proc)
# form_for(record_or_name_or_array, *(args << options.merge(
builder:
LabellingFormBuilder)), &proc)
# end
#
# If you don't need to attach a form to a model instance, then check out
...
...
@@ -403,13 +403,13 @@ module FormHelper
#
# To set an authenticity token you need to pass an <tt>:authenticity_token</tt> parameter
#
# <%= form_for @invoice,
:url => external_url, :authenticity_token =>
'external_token' do |f|
# <%= form_for @invoice,
url: external_url, authenticity_token:
'external_token' do |f|
# ...
# <% end %>
#
# If you don't want to an authenticity token field be rendered at all just pass <tt>false</tt>:
#
# <%= form_for @invoice,
:url => external_url, :authenticity_token =>
false do |f|
# <%= form_for @invoice,
url: external_url, authenticity_token:
false do |f|
# ...
# <% end %>
def
form_for
(
record
,
options
=
{},
&
proc
)
...
...
@@ -435,7 +435,7 @@ def form_for(record, options = {}, &proc)
builder
=
options
[
:parent_builder
]
=
instantiate_builder
(
object_name
,
object
,
options
)
fields_for
=
fields_for
(
object_name
,
object
,
options
,
&
proc
)
default_options
=
builder
.
multipart?
?
{
:multipart
=>
true
}
:
{}
default_options
=
builder
.
multipart?
?
{
multipart:
true
}
:
{}
default_options
.
merge!
(
options
.
delete
(
:html
))
form_tag
(
options
.
delete
(
:url
)
||
{},
default_options
)
{
fields_for
}
...
...
@@ -447,12 +447,12 @@ def apply_form_for_options!(record, object, options) #:nodoc:
as
=
options
[
:as
]
action
,
method
=
object
.
respond_to?
(
:persisted?
)
&&
object
.
persisted?
?
[
:edit
,
:patch
]
:
[
:new
,
:post
]
options
[
:html
].
reverse_merge!
(
:class
=>
as
?
"
#{
action
}
_
#{
as
}
"
:
dom_class
(
object
,
action
),
:id
=>
as
?
"
#{
action
}
_
#{
as
}
"
:
[
options
[
:namespace
],
dom_id
(
object
,
action
)].
compact
.
join
(
"_"
).
presence
,
:method
=>
method
class:
as
?
"
#{
action
}
_
#{
as
}
"
:
dom_class
(
object
,
action
),
id:
as
?
"
#{
action
}
_
#{
as
}
"
:
[
options
[
:namespace
],
dom_id
(
object
,
action
)].
compact
.
join
(
"_"
).
presence
,
method:
method
)
options
[
:url
]
||=
polymorphic_path
(
record
,
:format
=>
options
.
delete
(
:format
))
options
[
:url
]
||=
polymorphic_path
(
record
,
format:
options
.
delete
(
:format
))
end
private
:apply_form_for_options!
...
...
@@ -578,7 +578,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
#
# class Person < ActiveRecord::Base
# has_one :address
# accepts_nested_attributes_for :address,
:allow_destroy =>
true
# accepts_nested_attributes_for :address,
allow_destroy:
true
# end
#
# Now, when you use a form element with the <tt>_destroy</tt> parameter,
...
...
@@ -674,7 +674,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
#
# class Person < ActiveRecord::Base
# has_many :projects
# accepts_nested_attributes_for :projects,
:allow_destroy =>
true
# accepts_nested_attributes_for :projects,
allow_destroy:
true
# end
#
# This will allow you to specify which models to destroy in the
...
...
@@ -747,10 +747,10 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
# label(:post, :title, "A short title")
# # => <label for="post_title">A short title</label>
#
# label(:post, :title, "A short title",
:class =>
"title_label")
# label(:post, :title, "A short title",
class:
"title_label")
# # => <label for="post_title" class="title_label">A short title</label>
#
# label(:post, :privacy, "Public Post",
:value =>
"public")
# label(:post, :privacy, "Public Post",
value:
"public")
# # => <label for="post_privacy_public">Public Post</label>
#
# label(:post, :terms) do
...
...
@@ -766,18 +766,17 @@ def label(object_name, method, content_or_options = nil, options = nil, &block)
# shown.
#
# ==== Examples
# text_field(:post, :title,
:size =>
20)
# text_field(:post, :title,
size:
20)
# # => <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />
#
# text_field(:post, :title,
:class =>
"create_input")
# text_field(:post, :title,
class:
"create_input")
# # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" class="create_input" />
#
# text_field(:session, :user,
:onchange =>
"if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }")
# text_field(:session, :user,
onchange:
"if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }")
# # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange = "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }"/>
#
# text_field(:snippet, :code,
:size => 20, :class =>
'code_input')
# text_field(:snippet, :code,
size: 20, class:
'code_input')
# # => <input type="text" id="snippet_code" name="snippet[code]" size="20" value="#{@snippet.code}" class="code_input" />
#
def
text_field
(
object_name
,
method
,
options
=
{})
Tags
::
TextField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -788,18 +787,17 @@ def text_field(object_name, method, options = {})
# shown. For security reasons this field is blank by default; pass in a value via +options+ if this is not desired.
#
# ==== Examples
# password_field(:login, :pass,
:size =>
20)
# password_field(:login, :pass,
size:
20)
# # => <input type="password" id="login_pass" name="login[pass]" size="20" />
#
# password_field(:account, :secret,
:class => "form_input", :value =>
@account.secret)
# password_field(:account, :secret,
class: "form_input", value:
@account.secret)
# # => <input type="password" id="account_secret" name="account[secret]" value="#{@account.secret}" class="form_input" />
#
# password_field(:user, :password,
:onchange =>
"if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }")
# password_field(:user, :password,
onchange:
"if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }")
# # => <input type="password" id="user_password" name="user[password]" onchange = "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }"/>
#
# password_field(:account, :pin,
:size => 20, :class =>
'form_input')
# password_field(:account, :pin,
size: 20, class:
'form_input')
# # => <input type="password" id="account_pin" name="account[pin]" size="20" class="form_input" />
#
def
password_field
(
object_name
,
method
,
options
=
{})
Tags
::
PasswordField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -833,12 +831,11 @@ def hidden_field(object_name, method, options = {})
# file_field(:user, :avatar)
# # => <input type="file" id="user_avatar" name="user[avatar]" />
#
# file_field(:post, :attached,
:accept =>
'text/html')
# file_field(:post, :attached,
accept:
'text/html')
# # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
#
# file_field(:attachment, :file,
:class =>
'file_input')
# file_field(:attachment, :file,
class:
'file_input')
# # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
#
def
file_field
(
object_name
,
method
,
options
=
{})
Tags
::
FileField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -848,22 +845,22 @@ def file_field(object_name, method, options = {})
# hash with +options+.
#
# ==== Examples
# text_area(:post, :body,
:cols => 20, :rows =>
40)
# text_area(:post, :body,
cols: 20, rows:
40)
# # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
# # #{@post.body}
# # </textarea>
#
# text_area(:comment, :text,
:size =>
"20x30")
# text_area(:comment, :text,
size:
"20x30")
# # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
# # #{@comment.text}
# # </textarea>
#
# text_area(:application, :notes,
:cols => 40, :rows => 15, :class =>
'app_input')
# text_area(:application, :notes,
cols: 40, rows: 15, class:
'app_input')
# # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
# # #{@application.notes}
# # </textarea>
#
# text_area(:entry, :body,
:size => "20x20", :disabled =>
'disabled')
# text_area(:entry, :body,
size: "20x20", disabled:
'disabled')
# # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
# # #{@entry.body}
# # </textarea>
...
...
@@ -902,7 +899,7 @@ def text_area(object_name, method, options = {})
# Unfortunately that workaround does not work when the check box goes
# within an array-like parameter, as in
#
# <%= fields_for "project[invoice_attributes][]", invoice,
:index =>
nil do |form| %>
# <%= fields_for "project[invoice_attributes][]", invoice,
index:
nil do |form| %>
# <%= form.check_box :paid %>
# ...
# <% end %>
...
...
@@ -924,10 +921,9 @@ def text_area(object_name, method, options = {})
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
#
# check_box("eula", "accepted", {
:class =>
'eula_check' }, "yes", "no")
# check_box("eula", "accepted", {
class:
'eula_check' }, "yes", "no")
# # => <input name="eula[accepted]" type="hidden" value="no" />
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
#
def
check_box
(
object_name
,
method
,
options
=
{},
checked_value
=
"1"
,
unchecked_value
=
"0"
)
Tags
::
CheckBox
.
new
(
object_name
,
method
,
self
,
checked_value
,
unchecked_value
,
options
).
render
end
...
...
@@ -936,7 +932,7 @@ def check_box(object_name, method, options = {}, checked_value = "1", unchecked_
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
# radio button will be checked.
#
# To force the radio button to be checked pass <tt>
:checked =>
true</tt> in the
# To force the radio button to be checked pass <tt>
checked:
true</tt> in the
# +options+ hash. You may pass HTML options there as well.
#
# # Let's say that @post.category returns "rails":
...
...
@@ -957,7 +953,6 @@ def radio_button(object_name, method, tag_value, options = {})
#
# color_field("car", "color")
# # => <input id="car_color" name="car[color]" type="color" value="#000000" />
#
def
color_field
(
object_name
,
method
,
options
=
{})
Tags
::
ColorField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -968,18 +963,18 @@ def color_field(object_name, method, options = {})
#
# search_field(:user, :name)
# # => <input id="user_name" name="user[name]" type="search" />
# search_field(:user, :name,
:autosave =>
false)
# search_field(:user, :name,
autosave:
false)
# # => <input autosave="false" id="user_name" name="user[name]" type="search" />
# search_field(:user, :name,
:results =>
3)
# search_field(:user, :name,
results:
3)
# # => <input id="user_name" name="user[name]" results="3" type="search" />
# # Assume request.host returns "www.example.com"
# search_field(:user, :name,
:autosave =>
true)
# search_field(:user, :name,
autosave:
true)
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" type="search" />
# search_field(:user, :name,
:onsearch =>
true)
# search_field(:user, :name,
onsearch:
true)
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
# search_field(:user, :name,
:autosave => false, :onsearch =>
true)
# search_field(:user, :name,
autosave: false, onsearch:
true)
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
# search_field(:user, :name,
:autosave => true, :onsearch =>
true)
# search_field(:user, :name,
autosave: true, onsearch:
true)
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" type="search" />
def
search_field
(
object_name
,
method
,
options
=
{})
Tags
::
SearchField
.
new
(
object_name
,
method
,
self
,
options
).
render
...
...
@@ -1351,7 +1346,7 @@ def emitted_hidden_id?
private
def
objectify_options
(
options
)
@default_options
.
merge
(
options
.
merge
(
:object
=>
@object
))
@default_options
.
merge
(
options
.
merge
(
object:
@object
))
end
def
submit_default_value
...
...
@@ -1369,7 +1364,7 @@ def submit_default_value
defaults
<<
:"helpers.submit.
#{
key
}
"
defaults
<<
"
#{
key
.
to_s
.
humanize
}
#{
model
}
"
I18n
.
t
(
defaults
.
shift
,
:model
=>
model
,
:default
=>
defaults
)
I18n
.
t
(
defaults
.
shift
,
model:
model
,
default:
defaults
)
end
def
nested_attributes_association?
(
association_name
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录