#link_to not working in script/console
include ActionController::UrlWriter
#自定义时间和日期的格式,用来调用
在environment.rb你可以自定义时间和日期的格式 [Time::DATE_FORMATS, Date::DATE_FORMATS].each do |obj| obj[:dots] = "%m.%d.%y" end 在视图中就可以用了 Created: <%= @my_object.created_at.to_s(:dots) %>
#返回do 。。。。end这个块的处理结果(有时候为了省事和省却赋予新变量来return)
是个returning xxx 的这个xxx对象 def returns_a_hash(id) returning Hash.new do |result| result["id"] = id end end
#Rails这个module的信息
1.9.3p194 :073 > Rails.methods(false)
=> [:application, :application=, :configuration, :initialize!, :initialized?, :initialized=, :logger, :logger=, :backtrace_cleaner, :root, :env, :env=, :cache, :groups, :version, :public_path]
这里面有不少信息可以利用的,很方便。
1.9.3p194 :075 > Rails.public_path
=> "/***/public"
1.9.3p194 :076 > Rails.version
=> "3.2.13"
1.9.3p194 :077 > Rails.groups
=> [:default, "development"]
1.9.3p194 :090 > Rails.application.class
=> ***::Application
1.9.3p194 :091 > Rails.logger.class
=> ActiveSupport::TaggedLogging
1.9.3p194 :092 > Rails.configuration.class
=> Rails::Application::Configuration
1.9.3p194 :093 > Rails.root
=> #<Pathname:/***>
1.9.3p194 :094 > Rails.env
=> "development"
1.9.3p194 :095 > Rails.cache.class
=> ActiveSupport::Cache::FileStore
+
+
+
=
-
-
-