requireFile.expand_path('../boot',__FILE__)require'rails/all'ifdefined?(Bundler)# If you precompile assets before deploying to production, use this lineBundler.require(*Rails.groups(:assets=>%w(development test)))# If you want your assets lazily compiled in production, use this line# Bundler.require(:default, :assets, Rails.env)endmoduleRailsStudyclassApplication<Rails::Application# Settings in config/environments/* take precedence over those specified here.# Application configuration should go into files in config/initializers# -- all .rb files in that directory are automatically loaded.# Custom directories with classes and modules you want to be autoloadable.# config.autoload_paths += %W(#{config.root}/extras)# Only load the plugins named here, in the order given (default is alphabetical).# :all can be used as a placeholder for all plugins not explicitly named.# config.plugins = [ :exception_notification, :ssl_requirement, :all ]# Activate observers that should always be running.# config.active_record.observers = :cacher, :garbage_collector, :forum_observer# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.# config.time_zone = 'Central Time (US & Canada)'# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]config.i18n.default_locale="zh-CN"# Configure the default encoding used in templates for Ruby 1.9.config.encoding="utf-8"# Configure sensitive parameters which will be filtered from the log file.config.filter_parameters+=[:password]# Enable escaping HTML in JSON.config.active_support.escape_html_entities_in_json=true# Use SQL instead of Active Record's schema dumper when creating the database.# This is necessary if your schema can't be completely dumped by the schema dumper,# like if you have constraints or database-specific column types# config.active_record.schema_format = :sql# Enforce whitelist mode for mass assignment.# This will create an empty whitelist of attributes available for mass-assignment for all models# in your app. As such, your models will need to explicitly whitelist or blacklist accessible# parameters by using an attr_accessible or attr_protected declaration.config.active_record.whitelist_attributes=true# Enable the asset pipelineconfig.assets.enabled=true# Version of your assets, change this if you want to expire all your assetsconfig.assets.version='1.0'endend
moduleRailsclassRailtiemoduleConfigurableextendActiveSupport::ConcernmoduleClassMethodsdelegate:config,:to=>:instancedefinherited(base)raise"You cannot inherit from a #{self.superclass.name} child"enddefinstance@instance||=newend...endendendend
definitializer(name,opts={},&blk)raiseArgumentError,"A block must be passed when defining an initializer"unlessblkopts[:after]||=initializers.last.nameunlessinitializers.empty?||initializers.find{|i|i.name==opts[:before]}initializers<<Initializer.new(name,nil,opts,&blk)end
我们写的Gem包也可以是一个Engine应用,里面可以包含自己的controller,model,view文件,文件结构也可以和rails的文件结构一样,这样的构架很方便做一些通用的功能包,为减少重复代码提供了极大的方便。Engine本身还是有很多内容可以说的,关于如何应用他可以看看这个教程:Getting Started with Engines。
definitialize!(group=:default)#:nodoc:raise"Application has been already initialized."if@initializedrun_initializers(group,self)@initialized=trueselfend
defdefault_middleware_stackActionDispatch::MiddlewareStack.new.tapdo|middleware|ifrack_cache=config.action_controller.perform_caching&&config.action_dispatch.rack_cacherequire"action_dispatch/http/rack_cache"middleware.use::Rack::Cache,rack_cacheendifconfig.force_sslrequire"rack/ssl"middleware.use::Rack::SSL,config.ssl_optionsendifconfig.serve_static_assetsmiddleware.use::ActionDispatch::Static,paths["public"].first,config.static_cache_controlendmiddleware.use::Rack::Lockunlessconfig.allow_concurrencymiddleware.use::Rack::Runtimemiddleware.use::Rack::MethodOverridemiddleware.use::ActionDispatch::RequestIdmiddleware.use::Rails::Rack::Logger,config.log_tags# must come after Rack::MethodOverride to properly log overridden methodsmiddleware.use::ActionDispatch::ShowExceptions,config.exceptions_app||ActionDispatch::PublicExceptions.new(Rails.public_path)middleware.use::ActionDispatch::DebugExceptionsmiddleware.use::ActionDispatch::RemoteIp,config.action_dispatch.ip_spoofing_check,config.action_dispatch.trusted_proxiesifconfig.action_dispatch.x_sendfile_header.present?middleware.use::Rack::Sendfile,config.action_dispatch.x_sendfile_headerendunlessconfig.cache_classesapp=selfmiddleware.use::ActionDispatch::Reloader,lambda{app.reload_dependencies?}endmiddleware.use::ActionDispatch::Callbacksmiddleware.use::ActionDispatch::Cookiesifconfig.session_storeifconfig.force_ssl&&!config.session_options.key?(:secure)config.session_options[:secure]=trueendmiddleware.useconfig.session_store,config.session_optionsmiddleware.use::ActionDispatch::Flashendmiddleware.use::ActionDispatch::ParamsParsermiddleware.use::ActionDispatch::Headmiddleware.use::Rack::ConditionalGetmiddleware.use::Rack::ETag,"no-cache"ifconfig.action_dispatch.best_standards_supportmiddleware.use::ActionDispatch::BestStandardsSupport,config.action_dispatch.best_standards_supportendendend