Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d71b0935
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,发现更多精彩内容 >>
提交
d71b0935
编写于
5月 19, 2013
作者:
V
Vijay Dev
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:lifo/docrails
上级
d3d8cfd5
7f24d3d6
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
77 addition
and
25 deletion
+77
-25
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+13
-4
actionmailer/lib/action_mailer/delivery_methods.rb
actionmailer/lib/action_mailer/delivery_methods.rb
+1
-0
actionmailer/lib/action_mailer/log_subscriber.rb
actionmailer/lib/action_mailer/log_subscriber.rb
+5
-0
actionmailer/lib/action_mailer/mail_helper.rb
actionmailer/lib/action_mailer/mail_helper.rb
+3
-0
activerecord/lib/active_record/associations/builder/association.rb
...ord/lib/active_record/associations/builder/association.rb
+19
-0
activerecord/lib/active_record/associations/builder/collection_association.rb
...ive_record/associations/builder/collection_association.rb
+4
-0
activerecord/lib/active_record/associations/builder/singular_association.rb
...ctive_record/associations/builder/singular_association.rb
+4
-0
activerecord/lib/active_record/associations/collection_association.rb
.../lib/active_record/associations/collection_association.rb
+4
-4
activerecord/lib/active_record/associations/collection_proxy.rb
...record/lib/active_record/associations/collection_proxy.rb
+3
-3
activerecord/lib/active_record/querying.rb
activerecord/lib/active_record/querying.rb
+4
-3
activerecord/lib/rails/generators/active_record/model/model_generator.rb
...b/rails/generators/active_record/model/model_generator.rb
+4
-0
guides/source/active_record_validations.md
guides/source/active_record_validations.md
+7
-7
guides/source/migrations.md
guides/source/migrations.md
+4
-4
railties/lib/rails/generators/named_base.rb
railties/lib/rails/generators/named_base.rb
+2
-0
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
d71b0935
...
...
@@ -151,9 +151,9 @@ module ActionMailer
#
# For example, if the following templates exist:
# * signup_notification.text.erb
# * signup_notification.
text.
html.erb
# * signup_notification.
text.
xml.builder
# * signup_notification.
text.
yaml.erb
# * signup_notification.html.erb
# * signup_notification.xml.builder
# * signup_notification.yaml.erb
#
# Each would be rendered and added as a separate part to the message, with the corresponding content
# type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>,
...
...
@@ -175,7 +175,7 @@ module ActionMailer
# end
# end
#
# Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.
text.
html.erb</tt>
# Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.html.erb</tt>
# template in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
# the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
...
...
@@ -720,6 +720,15 @@ def mail(headers = {}, &block)
protected
# Used by #mail to set the content type of the message.
#
# It will use the given +user_content_type+, or multipart if the mail
# message has any attachments. If the attachments are inline, the content
# type will be "multipart/related", otherwise "multipart/mixed".
#
# If there is no content type passed in via headers, and there are no
# attachments, or the message is multipart, then the default content type is
# used.
def
set_content_type
(
m
,
user_content_type
,
class_default
)
params
=
m
.
content_type_parameters
||
{}
case
...
...
actionmailer/lib/action_mailer/delivery_methods.rb
浏览文件 @
d71b0935
...
...
@@ -38,6 +38,7 @@ module DeliveryMethods
add_delivery_method
:test
,
Mail
::
TestMailer
end
# Helpers for creating and wrapping delivery behavior, used by DeliveryMethods.
module
ClassMethods
# Provides a list of emails that have been delivered by Mail::TestMailer
delegate
:deliveries
,
:deliveries
=
,
to:
Mail
::
TestMailer
...
...
actionmailer/lib/action_mailer/log_subscriber.rb
浏览文件 @
d71b0935
module
ActionMailer
# Implements the ActiveSupport::LogSubscriber for logging notifications when
# email is delivered and received.
class
LogSubscriber
<
ActiveSupport
::
LogSubscriber
# An email was delivered.
def
deliver
(
event
)
return
unless
logger
.
info?
recipients
=
Array
(
event
.
payload
[
:to
]).
join
(
', '
)
...
...
@@ -7,12 +10,14 @@ def deliver(event)
debug
(
event
.
payload
[
:mail
])
end
# An email was received.
def
receive
(
event
)
return
unless
logger
.
info?
info
(
"
\n
Received mail (
#{
event
.
duration
.
round
(
1
)
}
ms)"
)
debug
(
event
.
payload
[
:mail
])
end
# Use the logger configured for ActionMailer::Base
def
logger
ActionMailer
::
Base
.
logger
end
...
...
actionmailer/lib/action_mailer/mail_helper.rb
浏览文件 @
d71b0935
module
ActionMailer
# Provides helper methods for ActionMailer::Base that can be used for easily
# formatting messages, accessing mailer or message instances, and the
# attachments list.
module
MailHelper
# Take the text and format it, indented two spaces for each line, and
# wrapped at 72 columns.
...
...
activerecord/lib/active_record/associations/builder/association.rb
浏览文件 @
d71b0935
# This is the parent Association class which defines the variables
# used by all associations.
#
# The hierarchy is defined as follows:
# Association
# - SingularAssociation
# - BelongsToAssociation
# - HasOneAssociation
# - CollectionAssociation
# - HasManyAssociation
# - HasAndBelongsToManyAssociation
module
ActiveRecord::Associations::Builder
class
Association
#:nodoc:
class
<<
self
...
...
@@ -58,6 +70,13 @@ def valid_options
def
validate_options
options
.
assert_valid_keys
(
valid_options
)
end
# Defines the setter and getter methods for the association
# class Post < ActiveRecord::Base
# has_many :comments
# end
#
# Post.first.comments and Post.first.comments= methods are defined by this method...
def
define_accessors
define_readers
...
...
activerecord/lib/active_record/associations/builder/collection_association.rb
浏览文件 @
d71b0935
# This class is inherited by the has_many and has_many_and_belongs_to_many association classes
require
'active_record/associations'
module
ActiveRecord::Associations::Builder
...
...
@@ -66,6 +68,8 @@ def define_callback(callback_name)
model
.
send
(
"
#{
full_callback_name
}
="
,
Array
(
options
[
callback_name
.
to_sym
]))
end
# Defines the setter and getter methods for the collection_singular_ids.
def
define_readers
super
...
...
activerecord/lib/active_record/associations/builder/singular_association.rb
浏览文件 @
d71b0935
# This class is inherited by the has_one and belongs_to association classes
module
ActiveRecord::Associations::Builder
class
SingularAssociation
<
Association
#:nodoc:
def
valid_options
...
...
@@ -13,6 +15,8 @@ def define_accessors
define_constructors
if
constructable?
end
# Defines the (build|create)_association methods for belongs_to or has_one association
def
define_constructors
mixin
.
class_eval
<<-
CODE
,
__FILE__
,
__LINE__
+
1
def build_
#{
name
}
(*args, &block)
...
...
activerecord/lib/active_record/associations/collection_association.rb
浏览文件 @
d71b0935
...
...
@@ -237,11 +237,11 @@ def delete(*records)
end
end
# De
stroy +records+ and remove
them from this association calling
# +before_remove+
and +after_remove
+ callbacks.
# De
letes the +records+ and removes
them from this association calling
# +before_remove+
, +after_remove+ , +before_destroy+ and +after_destroy
+ callbacks.
#
# Note that this method
will _always_ remove records from the databas
e
#
ignoring the
+:dependent+ option.
# Note that this method
removes records from the database ignoring th
e
# +:dependent+ option.
def
destroy
(
*
records
)
records
=
find
(
records
)
if
records
.
any?
{
|
record
|
record
.
kind_of?
(
Fixnum
)
||
record
.
kind_of?
(
String
)
}
delete_or_destroy
(
records
,
:destroy
)
...
...
activerecord/lib/active_record/associations/collection_proxy.rb
浏览文件 @
d71b0935
...
...
@@ -422,9 +422,9 @@ def delete_all
@association
.
delete_all
end
# Deletes the records of the collection directly from the database
.
#
This will _always_ remove the records ignoring the +:dependent+
#
option
.
# Deletes the records of the collection directly from the database
#
ignoring the +:dependent+ option. It invokes +before_remove+,
#
+after_remove+ , +before_destroy+ and +after_destroy+ callbacks
.
#
# class Person < ActiveRecord::Base
# has_many :pets
...
...
activerecord/lib/active_record/querying.rb
浏览文件 @
d71b0935
...
...
@@ -14,7 +14,7 @@ module Querying
# Executes a custom SQL query against your database and returns all the results. The results will
# be returned as an array with columns requested encapsulated as attributes of the model you call
# this method from. If you call <tt>Product.find_by_sql</tt> then the results will be returned in
# a
Product
object with the attributes you specified in the SQL query.
# a
+Product+
object with the attributes you specified in the SQL query.
#
# If you call a complicated SQL query which spans multiple tables the columns specified by the
# SELECT will be attributes of the model, whether or not they are columns of the corresponding
...
...
@@ -29,9 +29,10 @@ module Querying
# Post.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id"
# # => [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "first_name"=>"Quentin"}>, ...]
#
# # You can use the same string replacement techniques as you can with ActiveRecord#find
# You can use the same string replacement techniques as you can with <tt>ActiveRecord::QueryMethods#where</tt>:
#
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
#
# => [#<Post:0x36bff9c @attributes={"title"=>"The Cheap Man Buys Twice"}>, ...
]
#
Post.find_by_sql ["SELECT body FROM comments WHERE author = :user_id OR approved_by = :user_id", { :user_id => user_id }
]
def
find_by_sql
(
sql
,
binds
=
[])
result_set
=
connection
.
select_all
(
sanitize_sql
(
sql
),
"
#{
name
}
Load"
,
binds
)
column_types
=
{}
...
...
activerecord/lib/rails/generators/active_record/model/model_generator.rb
浏览文件 @
d71b0935
...
...
@@ -12,6 +12,9 @@ class ModelGenerator < Base # :nodoc:
class_option
:parent
,
:type
=>
:string
,
:desc
=>
"The parent class for the generated model"
class_option
:indexes
,
:type
=>
:boolean
,
:default
=>
true
,
:desc
=>
"Add indexes for references and belongs_to columns"
# creates the migration file for the model.
def
create_migration_file
return
unless
options
[
:migration
]
&&
options
[
:parent
].
nil?
attributes
.
each
{
|
a
|
a
.
attr_options
.
delete
(
:index
)
if
a
.
reference?
&&
!
a
.
has_index?
}
if
options
[
:indexes
]
==
false
...
...
@@ -39,6 +42,7 @@ def accessible_attributes
protected
# Used by the migration template to determine the parent name of the model
def
parent_class_name
options
[
:parent
]
||
"ActiveRecord::Base"
end
...
...
guides/source/active_record_validations.md
浏览文件 @
d71b0935
...
...
@@ -162,8 +162,8 @@ Person.create(name: nil).valid? # => false
```
After Active Record has performed validations, any errors found can be accessed
through the
`errors
`
instance method, which returns a collection of errors. By
definition, an object is valid if this collection is empty after running
through the
`errors
.messages`
instance method, which returns a collection of errors.
By
definition, an object is valid if this collection is empty after running
validations.
Note that an object instantiated with
`new`
will not report errors even if it's
...
...
@@ -176,17 +176,17 @@ end
>>
p
=
Person
.
new
#=> #<Person id: nil, name: nil>
>>
p
.
errors
>>
p
.
errors
.
messages
#=> {}
>>
p
.
valid?
#=> false
>>
p
.
errors
>>
p
.
errors
.
messages
#=> {name:["can't be blank"]}
>>
p
=
Person
.
create
#=> #<Person id: nil, name: nil>
>>
p
.
errors
>>
p
.
errors
.
messages
#=> {name:["can't be blank"]}
>>
p
.
save
...
...
@@ -993,12 +993,12 @@ end
person
=
Person
.
new
person
.
valid?
# => false
person
.
errors
person
.
errors
.
messages
# => {:name=>["can't be blank", "is too short (minimum is 3 characters)"]}
person
=
Person
.
new
(
name:
"John Doe"
)
person
.
valid?
# => true
person
.
errors
# => []
person
.
errors
.
messages
# => {}
```
### `errors[]`
...
...
guides/source/migrations.md
浏览文件 @
d71b0935
...
...
@@ -852,7 +852,7 @@ end
# app/models/product.rb
class
Product
<
ActiveRecord
::
Base
validates
:flag
,
:inclusion
=>
{
:in
=>
[
true
,
false
]
}
validates
:flag
,
inclusion:
{
in:
[
true
,
false
]
}
end
```
...
...
@@ -877,7 +877,7 @@ end
# app/models/product.rb
class
Product
<
ActiveRecord
::
Base
validates
:flag
,
:inclusion
=>
{
:in
=>
[
true
,
false
]
}
validates
:flag
,
inclusion:
{
in:
[
true
,
false
]
}
validates
:fuzz
,
presence:
true
end
```
...
...
@@ -1065,8 +1065,8 @@ with foreign key constraints in the database.
Although Active Record does not provide any tools for working directly with
such features, the
`execute`
method can be used to execute arbitrary SQL. You
c
ould also use some
gem like
[
foreigner
](
https://github.com/matthuhiggins/foreigner
)
which add foreign key
c
an also use a
gem like
[
foreigner
](
https://github.com/matthuhiggins/foreigner
)
which add
s
foreign key
support to Active Record (including support for dumping foreign keys in
`db/schema.rb`
).
...
...
railties/lib/rails/generators/named_base.rb
浏览文件 @
d71b0935
...
...
@@ -18,6 +18,8 @@ def initialize(args, *options) #:nodoc:
parse_attributes!
if
respond_to?
(
:attributes
)
end
# Defines the template that would be used for the migration file.
# The arguments include the source template file, the migration filename etc.
no_tasks
do
def
template
(
source
,
*
args
,
&
block
)
inside_template
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录