提交 7b0e1cb0 编写于 作者: V Vijay Dev

Merge branch 'master' of github.com:lifo/docrails

...@@ -570,13 +570,13 @@ def controller(controller, options={}) ...@@ -570,13 +570,13 @@ def controller(controller, options={})
# #
# This generates the following routes: # This generates the following routes:
# #
# admin_posts GET /admin/posts(.:format) {:action=>"index", :controller=>"admin/posts"} # admin_posts GET /admin/posts(.:format) {:action=>"index", :controller=>"admin/posts"}
# admin_posts POST /admin/posts(.:format) {:action=>"create", :controller=>"admin/posts"} # admin_posts POST /admin/posts(.:format) {:action=>"create", :controller=>"admin/posts"}
# new_admin_post GET /admin/posts/new(.:format) {:action=>"new", :controller=>"admin/posts"} # new_admin_post GET /admin/posts/new(.:format) {:action=>"new", :controller=>"admin/posts"}
# edit_admin_post GET /admin/posts/:id/edit(.:format) {:action=>"edit", :controller=>"admin/posts"} # edit_admin_post GET /admin/posts/:id/edit(.:format) {:action=>"edit", :controller=>"admin/posts"}
# admin_post GET /admin/posts/:id(.:format) {:action=>"show", :controller=>"admin/posts"} # admin_post GET /admin/posts/:id(.:format) {:action=>"show", :controller=>"admin/posts"}
# admin_post PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"} # admin_post PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"}
# admin_post DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"} # admin_post DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"}
# === Supported options # === Supported options
# #
# The +:path+, +:as+, +:module+, +:shallow_path+ and +:shallow_prefix+ options all default to the name of the namespace. # The +:path+, +:as+, +:module+, +:shallow_path+ and +:shallow_prefix+ options all default to the name of the namespace.
...@@ -584,24 +584,24 @@ def controller(controller, options={}) ...@@ -584,24 +584,24 @@ def controller(controller, options={})
# [:path] # [:path]
# The path prefix for the routes. # The path prefix for the routes.
# #
# namespace :admin, :path => "sekret" do # namespace :admin, :path => "sekret" do
# resources :posts # resources :posts
# end # end
# #
# All routes for the above +resources+ will be accessible through +/sekret/posts+, rather than +/admin/posts+ # All routes for the above +resources+ will be accessible through +/sekret/posts+, rather than +/admin/posts+
# #
# [:module] # [:module]
# The namespace for the controllers. # The namespace for the controllers.
# #
# namespace :admin, :module => "sekret" do # namespace :admin, :module => "sekret" do
# resources :posts # resources :posts
# end # end
# #
# The +PostsController+ here should go in the +Sekret+ namespace and so it should be defined like this: # The +PostsController+ here should go in the +Sekret+ namespace and so it should be defined like this:
# #
# class Sekret::PostsController < ApplicationController # class Sekret::PostsController < ApplicationController
# # code go here # # code go here
# end # end
# #
# [:as] # [:as]
# Changes the name used in routing helpers for this namespace. # Changes the name used in routing helpers for this namespace.
......
...@@ -1115,7 +1115,7 @@ class InstanceTag ...@@ -1115,7 +1115,7 @@ class InstanceTag
include InstanceTagMethods include InstanceTagMethods
end end
class FormBuilder #:nodoc: class FormBuilder
# The methods which wrap a form helper call. # The methods which wrap a form helper call.
class_attribute :field_helpers class_attribute :field_helpers
self.field_helpers = (FormHelper.instance_method_names - ['form_for']) self.field_helpers = (FormHelper.instance_method_names - ['form_for'])
......
...@@ -68,7 +68,7 @@ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block) ...@@ -68,7 +68,7 @@ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
# * Any other key creates standard HTML attributes for the tag. # * Any other key creates standard HTML attributes for the tag.
# #
# ==== Examples # ==== Examples
# select_tag "people", options_from_collection_for_select(@people, "name", "id") # select_tag "people", options_from_collection_for_select(@people, "id", "name")
# # <select id="people" name="people"><option value="1">David</option></select> # # <select id="people" name="people"><option value="1">David</option></select>
# #
# select_tag "people", "<option>David</option>" # select_tag "people", "<option>David</option>"
...@@ -112,6 +112,7 @@ def select_tag(name, option_tags = nil, options = {}) ...@@ -112,6 +112,7 @@ def select_tag(name, option_tags = nil, options = {})
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input. # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
# * <tt>:size</tt> - The number of visible characters that will fit in the input. # * <tt>:size</tt> - The number of visible characters that will fit in the input.
# * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter. # * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter.
# * <tt>:placeholder</tt> - The text contained in the field by default which is removed when the field receives focus.
# * Any other key creates standard HTML attributes for the tag. # * Any other key creates standard HTML attributes for the tag.
# #
# ==== Examples # ==== Examples
...@@ -121,6 +122,9 @@ def select_tag(name, option_tags = nil, options = {}) ...@@ -121,6 +122,9 @@ def select_tag(name, option_tags = nil, options = {})
# text_field_tag 'query', 'Enter your search query here' # text_field_tag 'query', 'Enter your search query here'
# # => <input id="query" name="query" type="text" value="Enter your search query here" /> # # => <input id="query" name="query" type="text" value="Enter your search query here" />
# #
# text_field_tag 'search', nil, :placeholder => 'Enter search term...'
# # => <input id="search" name="search" placeholder="Enter search term..." type="text" />
#
# text_field_tag 'request', nil, :class => 'special_input' # text_field_tag 'request', nil, :class => 'special_input'
# # => <input class="special_input" id="request" name="request" type="text" /> # # => <input class="special_input" id="request" name="request" type="text" />
# #
......
...@@ -414,7 +414,7 @@ class Person < ActiveRecord::Base ...@@ -414,7 +414,7 @@ class Person < ActiveRecord::Base
validates_with GoodnessValidator validates_with GoodnessValidator
end end
class GoodnessValidator < ActiveRecord::Validator class GoodnessValidator < ActiveModel::Validator
def validate def validate
if record.first_name == "Evil" if record.first_name == "Evil"
record.errors[:base] << "This person is evil" record.errors[:base] << "This person is evil"
......
...@@ -3359,6 +3359,49 @@ The auxiliary file is written in a standard directory for temporary files, but y ...@@ -3359,6 +3359,49 @@ The auxiliary file is written in a standard directory for temporary files, but y
NOTE: Defined in +active_support/core_ext/file/atomic.rb+. NOTE: Defined in +active_support/core_ext/file/atomic.rb+.
h3. Extensions to +Logger+
h4. +around_[level]+
Takes two arguments, a +before_message+ and +after_message+ and calls the current level method on the +Logger+ instance, passing in the +before_message+, then the specified message, then the +after_message+:
<ruby>
logger = Logger.new("log/development.log")
logger.around_info("before", "after") { |logger| logger.info("during") }
</ruby>
h4. +silence+
Silences every log level lesser to the specified one for the duration of the given block. Log level orders are: debug, info, error and fatal.
<ruby>
logger = Logger.new("log/development.log")
logger.silence(Logger::INFO) do
logger.debug("In space, no one can hear you scream.")
logger.info("Scream all you want, small mailman!")
end
</ruby>
h4. +datetime_format=+
Modifies the datetime format output by the formatter class associated with this logger. If the formatter class does not have a +datetime_format+ method then this is ignored.
<ruby>
class Logger::FormatWithTime < Logger::Formatter
cattr_accessor(:datetime_format) { "%Y%m%d%H%m%S" }
def self.call(severity, timestamp, progname, msg)
"#{timestamp.strftime(datetime_format)} -- #{String === msg ? msg : msg.inspect}\n"
end
end
logger = Logger.new("log/development.log")
logger.formatter = Logger::FormatWithTime
logger.info("<- is the current time")
</ruby>
NOTE: Defined in +active_support/core_ext/logger.rb+.
h3. Extensions to +NameError+ h3. Extensions to +NameError+
Active Support adds +missing_name?+ to +NameError+, which tests whether the exception was raised because of the name passed as argument. Active Support adds +missing_name?+ to +NameError+, which tests whether the exception was raised because of the name passed as argument.
......
...@@ -595,7 +595,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method: ...@@ -595,7 +595,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method:
root :to => 'pages#main' root :to => 'pages#main'
</ruby> </ruby>
You should put the +root+ route at the end of the file. You should put the +root+ route at the end of the file. You also need to delete the public/index.html.erb file for the root route to take effect.
h3. Customizing Resourceful Routes h3. Customizing Resourceful Routes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册