KEY REQUEST.docx
- 文档编号:12205403
- 上传时间:2023-04-17
- 格式:DOCX
- 页数:25
- 大小:30.81KB
KEY REQUEST.docx
《KEY REQUEST.docx》由会员分享,可在线阅读,更多相关《KEY REQUEST.docx(25页珍藏版)》请在冰豆网上搜索。
KEYREQUEST
1LocationsforInitializationCode
Railsoffersfourstandardspotstoplaceinitializationcode:
∙config/application.rb
∙Environment-specificconfigurationfiles
∙Initializers
∙After-initializers
2RunningCodeBeforeRails
IntherareeventthatyourapplicationneedstorunsomecodebeforeRailsitselfisloaded,putitabovethecalltorequire'rails/all'inconfig/application.rb.
3ConfiguringRailsComponents
Ingeneral,theworkofconfiguringRailsmeansconfiguringthecomponentsofRails,aswellasconfiguringRailsitself.Theconfigurationfileconfig/application.rbandenvironment-specificconfigurationfiles(suchasconfig/environments/production.rb)allowyoutospecifythevarioussettingsthatyouwanttopassdowntoallofthecomponents.
Forexample,thedefaultconfig/application.rbfileincludesthissetting:
config.filter_parameters+=[:
password]
ThisisasettingforRailsitself.IfyouwanttopasssettingstoindividualRailscomponents,youcandosoviathesameconfigobjectinconfig/application.rb:
config.active_record.observers=[:
hotel_observer,:
review_observer]
RailswillusethatparticularsettingtoconfigureActiveRecord.
3.1RailsGeneralConfiguration
∙config.after_initializetakesablockwhichwillberanafterRailshasfinishedinitializingtheapplication.Thatincludestheinitializationoftheframeworkitself,plugins,engines,andalltheapplication’sinitializersinconfig/initializers.Usefulforconfiguringvaluessetupbyotherinitializers:
config.after_initializedo
ActionView:
:
Base.sanitized_allowed_tags.delete'div'
end
∙config.allow_concurrencyshouldbetruetoallowconcurrent(threadsafe)actionprocessing.Falsebydefault.Youprobablydon’twanttocallthisonedirectly,though,becauseaseriesofotheradjustmentsneedtobemadeforthreadsafemodetoworkproperly.Canalsobeenabledwiththreadsafe!
.
∙config.asset_hostsetsthehostfortheassets.UsefulwhenCDNsareusedforhostingassets,orwhenyouwanttoworkaroundtheconcurrencyconstraintsbuiltininbrowsersusingdifferentdomainaliases.Shorterversionofconfig.action_controller.asset_host.
∙config.asset_pathletsyoudecorateassetpaths.Thiscanbeacallable,astring,orbenilwhichisthedefault.Forexample,thenormalpathforblog.jswouldbe/javascripts/blog.js,letthatabsolutepathbepath.Ifconfig.asset_pathisacallable,Railscallsitwhengeneratingassetpathspassingpathasargument.Ifconfig.asset_pathisastring,itisexpectedtobeasprintfformatstringwitha%swherepathwillgetinserted.Ineithercase,Railsoutputsthedecoratedpath.Shorterversionofconfig.action_controller.asset_path.
config.asset_path=proc{|path|"/blog/public#{path}"}
Theconfig.asset_pathconfigurationisignorediftheassetpipelineisenabled,whichisthedefault.
∙config.autoload_once_pathsacceptsanarrayofpathsfromwhichRailswillautoloadconstantsthatwon’tbewipedperrequest.Relevantifconfig.cache_classesisfalse,whichisthecaseindevelopmentmodebydefault.Otherwise,allautoloadinghappensonlyonce.Allelementsofthisarraymustalsobeinautoload_paths.Defaultisanemptyarray.
∙config.autoload_pathsacceptsanarrayofpathsfromwhichRailswillautoloadconstants.Defaultisalldirectoriesunderapp.
∙config.cache_classescontrolswhetherornotapplicationclassesandmodulesshouldbereloadedoneachrequest.Defaultstotrueindevelopmentmode,andfalseintestandproductionmodes.Canalsobeenabledwiththreadsafe!
.
∙config.action_view.cache_template_loadingcontrolswhetherornottemplatesshouldbereloadedoneachrequest.Defaultstowhateverissetforconfig.cache_classes.
∙config.cache_storeconfigureswhichcachestoretouseforRailscaching.Optionsincludeoneofthesymbols:
memory_store,:
file_store,:
mem_cache_store,oranobjectthatimplementsthecacheAPI.Defaultsto:
file_storeifthedirectorytmp/cacheexists,andto:
memory_storeotherwise.
∙config.colorize_loggingspecifieswhetherornottouseANSIcolorcodeswhenlogginginformation.Defaultstotrue.
∙config.consider_all_requests_localisaflag.IftruethenanyerrorwillcausedetaileddebugginginformationtobedumpedintheHTTPresponse,andtheRails:
:
Infocontrollerwillshowtheapplicationruntimecontextin/rails/info/properties.Truebydefaultindevelopmentandtestenvironments,andfalseinproductionmode.Forfiner-grainedcontrol,setthistofalseandimplementlocal_request?
incontrollerstospecifywhichrequestsshouldprovidedebugginginformationonerrors.
∙config.dependency_loadingisaflagthatallowsyoutodisableconstantautoloadingsettingittofalse.Itonlyhaseffectifconfig.cache_classesistrue,whichitisbydefaultinproductionmode.Thisflagissettofalsebyconfig.threadsafe!
.
∙config.eager_load_pathsacceptsanarrayofpathsfromwhichRailswilleagerloadonbootifcacheclassesisenabled.Defaultstoeveryfolderintheappdirectoryoftheapplication.
∙config.encodingsetsuptheapplication-wideencoding.DefaultstoUTF-8.
∙config.filter_parametersusedforfilteringouttheparametersthatyoudon’twantshowninthelogs,suchaspasswordsorcreditcardnumbers.
∙config.force_sslforcesallrequeststobeunderHTTPSprotocolbyusingRack:
:
SSLmiddleware.
∙config.log_leveldefinestheverbosityoftheRailslogger.Thisoptiondefaultsto:
debugforallmodesexceptproduction,whereitdefaultsto:
info.
∙config.loggeracceptsaloggerconformingtotheinterfaceofLog4rorthedefaultRubyLoggerclass.DefaultstoaninstanceofActiveSupport:
:
BufferedLogger,withautoflushingoffinproductionmode.
∙config.middlewareallowsyoutoconfiguretheapplication’smiddleware.ThisiscoveredindepthintheConfiguringMiddlewaresectionbelow.
∙config.pluginsacceptsthelistofpluginstoload.Thedefaultisnilinwhichcaseallpluginswillbeloaded.Ifthisissetto[],nopluginswillbeloaded.Otherwise,pluginswillbeloadedintheorderspecified.Thisoptionletsyouenforcesomeparticularloadingorder,usefulwhendependenciesbetweenpluginsrequireit.Forthatusecase,putfirstthepluginsyouwanttobeloadedinacertainorder,andthenthespecialsymbol:
alltohavetherestloadedwithouttheneedtospecifythem.
∙config.preload_frameworksenablesordisablespreloadingallframeworksatstartup.Enabledbyconfig.threadsafe!
.Defaultstonil,soisdisabled.
∙config.reload_pluginsenablesordisablespluginreloading.Defaultstofalse.
∙config.secret_tokenusedforspecifyingakeywhichallowssessionsfortheapplicationtobeverifiedagainstaknownsecurekeytopreventtampering.Applicationsgetconfig.secret_tokeninitializedtoarandomkeyinconfig/initializers/secret_token.rb.
∙config.serve_static_assetsconfiguresRailsitselftoservestaticassets.Defaultstotrue,butintheproductionenvironmentisturnedoffastheserversoftware(e.g.NginxorApache)usedtoruntheapplicationshouldservestaticassetsinstead.Unlikethedefaultsettingsetthistotruewhenrunning(absolutelynotrecommended!
)ortestingyourappinproductionmodeusingWEBrick.Otherwiseyouwon´tbeableusepagecachingandrequestsforfilesthatexistregularlyunderthepublicdirectorywillanywayhityourRailsapp.
∙config.session_storeisusuallysetupinconfig/initializers/session_store.rbandspecifieswhatclasstousetostorethesession.Possiblevaluesare:
cookie_storewhichisthedefault,:
mem_cache_store,and:
disabled.ThelastonetellsRailsnottodealwithsessions.Customsessionstorescanalsobespecified:
config.session_store:
my_custom_store
ThiscustomstoremustbedefinedasActionDispatch:
:
Session:
:
MyCustomStore.Inadditiontosymbols,theycanalsobeobjectsimplementingacertainAPI,likeActiveRecord:
:
SessionStore,inwhichcasenospecialnamespaceisrequired.
∙config.threadsafe!
enablesallow_concurrency,cache_classes,dependency_loadingandpreload_frameworkstomaketheapplicationthreadsafe.
ThreadsafeoperationisincompatiblewiththenormalworkingsofdevelopmentmodeRails.Inparticular,automaticdependencyloadingandclassreloadingareautomaticallydisabledwhenyoucallconfig.threadsafe!
.
∙config.time_zonesetsthedefaulttimezonefortheapplicationandenablestimezoneawarenessforActiveRecord.
∙config.whiny_nilsenablesordisableswarningswhenacertainsetofmethodsareinvokedonnilanditdoesnotrespondtothem.Defaultstotrueindevelopmentandtestenvironments.
3.2ConfiguringAssets
Rails3.1,bydefault,issetuptousethesprocketsgemtomanageassetswithinanapplication.Thisgemconcatenatesandcompressesassetsinordertomakeservingthemmuchlesspainful.
∙config.assets.enabledaflagthatcontrolswhethertheassetpipelineisenabled.Itisexplicitlyinitializedinconfig/application.rb.
∙pressaflagthatenablesthecompressionofcompiledassets.Itisexplicitlysettotrueinconfig/production.rb.
∙config.assets.css_compressordefinestheCSScompressortouse.Itissetbydefaultbysass-rails.Theuniquealternativevalueatthemomentis:
yui,whichusestheyui-compressorgem.
∙config.assets.js_compressordefinestheJavaScriptcompressortouse.Possiblevaluesare:
closure,:
uglifierand:
yuiwhichrequiretheuseoftheclosure-compiler,uglifieroryui-compressorgemsrespectively.
∙config.assets.pathscontainsthepathswhichareusedtolookforassets.Appendingpathstothisconfigurationoptionwillcausethosepathstobeusedinthesearchforassets.
∙config.assets.precompileallowsyoutospecifyadditionalassets
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- KEY REQUEST