1
| if Rails.env.development?
|
1
| pluralize(count, "error")
|
1
2
3
4
| 1.kilobyte #千字节
#=>1024
5.megabytes #上传文件限制字节数5M
#=> 5242880
|
1
2
3
4
| User.new.new_record?
#=>true
User.first.new_record?
#=>false
|
1
| time_ago_in_words(model.created_at)
|
1
2
3
4
5
6
7
8
9
10
11
12
| def show
@list_item = @list.list_items.find( params[ :id ] )
if stale?( :etag => @list_item, :last_modified => @list_item.updated_at.utc, :public => true )
respond_with( @list_item )
end
end
=begin
stale?语句会通过响应发送回一个etag与一个last_modified日期。如果下一个请求是相同的URL,
那么浏览器会把这个etag和last_modified日期发送给服务器。然后stale?方法会对这两个参数进行分析,
如果内容相同,则返回304,如果出现参数值不同,那么说明有新的内容,这样返回200。
=end
|
1
| rails new app_name --skip-active-record
|
1
2
| raw ('string')
'string'.html_safe
|
1
2
| <%= date_select :variable, :attribute, options %>
<%= datetime_select :variable, :attribute, options %>
|
1
2
3
| "Person".tableize # => "people"
"Invoice".tableize # => "invoices"
"InvoiceLine".tableize # => "invoice_lines"
|