我有这个字符串'custom_controller'。
我需要把它带到'CustomController'。
它来自所需的文件名,需要内部的类名。
要切入追逐,代码为here。
这是一个来自Github的Rack教程的项目。 rack/rack/wiki/Tutorials
但是,不仅仅将它们命名为custom.rb和类Custom,我希望它更像Rails应用程序而不需要Rails或Rails附带的任何宝石,除了Rack。 这不是Rails应用程序。这甚至不是Sinatra或Padrino应用程序。它只是一个使用Rack的家庭酿造网络框架。
答案 0 :(得分:2)
您可以使用普通红宝石来构建自己的CAST
方法。
camelize
答案 1 :(得分:2)
这也有效:
<div id="facilities_suggestions_list" class="suggestions_list">
<h3>Experience</h3>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120063:-122.595:37.9038889::CA", "120063", 1 )" id="suggestion_1_120063"><strong>MOUNT</strong> <strong>TAMALPAIS</strong> <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120061:-121.93:37.8627778::CA", "120061", 1 )" id="suggestion_1_120061"><strong>MT.</strong> DIABLO <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120062:-116.675:33.8102778::CA", "120062", 1 )" id="suggestion_1_120062"><strong>MT.</strong> SAN JACINTO <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:70045:-106.2227778:38.7141667::CO", "70045", 1 )" id="suggestion_1_70045"><strong>MOUNT</strong> PRINCETON <span>, CO</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:70124:-111.6036111:40.4061111::UT", "70124", 1 )" id="suggestion_1_70124"><strong>MT.</strong> TIMPANOGOS <span>, UT</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281003:-81.2802778:29.8772222::FL", "281003", 1 )" id="suggestion_1_281003">ANASTASIA <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120013:-122.3022222:37.2227778::CA", "120013", 1 )" id="suggestion_1_120013">BUTANO <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NE:230042:-103.0197222:42.7091667::NE", "230042", 1 )" id="suggestion_1_230042">Chadron <strong>SP</strong> <span>, NE</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120035:-120.065:34.4622222::CA", "120035", 1 )" id="suggestion_1_120035">GAVIOTA <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120048:-121.5694444:36.0530556::CA", "120048", 1 )" id="suggestion_1_120048">LIMEKILN <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120049:-123.7925:39.4933333::CA", "120049", 1 )" id="suggestion_1_120049">MACKERRICHER <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120052:-123.7113889:38.9738889::CA", "120052", 1 )" id="suggestion_1_120052">MANCHESTER <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281060:-82.6033333:29.9194444::FL", "281060", 1 )" id="suggestion_1_281060">OLENO <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NE:230143:-96.7172222:42.6097222::NE", "230143", 1 )" id="suggestion_1_230143">Ponca <strong>SP</strong> <span>, NE</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281076:-81.0836111:29.3408333::FL", "281076", 1 )" id="suggestion_1_281076">TOMOKA <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281077:-84.9505556:30.5697222::FL", "281077", 1 )" id="suggestion_1_281077">TORREYA <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120097:-123.7733333:39.2763889::CA", "120097", 1 )" id="suggestion_1_120097">VANDAMME <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:71897:-131.8988889:56.6441667::AK", "71897", 1 )" id="suggestion_1_71897"><strong>MOUNT</strong> FLEMER CABIN <span>, AK</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:75021:-82.7566667:35.4027778::NC", "75021", 1 )" id="suggestion_1_75021"><strong>MOUNT</strong> PISGAH CAMPGROUND <span>, NC</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:70459:-119.8973611:39.3122778::CA", "70459", 1 )" id="suggestion_1_70459"><strong>MOUNT</strong> ROSE (NV) <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NRSO:71896:-132.2391667:56.6644444::AK", "71896", 1 )" id="suggestion_1_71896"><strong>MOUNT</strong> RYNDA CABIN <span>, AK</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120003:-122.4308333:37.8641667::CA", "120003", 1 )" id="suggestion_1_120003">ANGEL ISLAND <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281005:-81.2741667:24.6597222::FL", "281005", 1 )" id="suggestion_1_281005">BAHIA HONDA <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281128:-87.4038889:30.3180556::FL", "281128", 1 )" id="suggestion_1_281128">BIG LAGOON <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281008:-86.8783333:30.7116667::FL", "281008", 1 )" id="suggestion_1_281008">BLACKWATER RIVER <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281101:-81.3338889:28.9508333::FL", "281101", 1 )" id="suggestion_1_281101">Blue Spring <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281010:-82.8197222:28.0311111::FL", "281010", 1 )" id="suggestion_1_281010">CALADESI ISLAND <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120016:-122.3505556:41.1711111::CA", "120016", 1 )" id="suggestion_1_120016">CASTLE CRAGS <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120017:-121.1866667:37.6933333::CA", "120017", 1 )" id="suggestion_1_120017">CASWELL MEMORIAL <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281127:-82.2452778:26.6858333::FL", "281127", 1 )" id="suggestion_1_281127">CAYO COSTA <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120018:-122.4605556:38.0008333::CA", "120018", 1 )" id="suggestion_1_120018">CHINA CAMP <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:124900::::CA", "124900", 1 )" id="suggestion_1_124900">CHINO HILLS <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120019:-122.8141667:39.0066667::CA", "120019", 1 )" id="suggestion_1_120019">CLEAR LAKE <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281013:-81.5913889:25.9916667::FL", "281013", 1 )" id="suggestion_1_281013">COLLIER-SEMINOLE <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281228:-80.985:24.7422222::FL", "281228", 1 )" id="suggestion_1_281228">CURRY HAMMOCK <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120023:-116.5616667:32.9358333::CA", "120023", 1 )" id="suggestion_1_120023">CUYAMACA RANCHO <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120029:-120.2419444:39.32::CA", "120029", 1 )" id="suggestion_1_120029">DONNER MEMORIAL <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120031:-120.0930556:38.9544444::CA", "120031", 1 )" id="suggestion_1_120031">EMERALD BAY <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281021:-85.5288889:30.7308333::FL", "281021", 1 )" id="suggestion_1_281021">FALLING WATERS <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281241:-82.9347222:29.5861111::FL", "281241", 1 )" id="suggestion_1_281241">FANNING SPRINGS <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281022:-81.2686111:29.6675::FL", "281022", 1 )" id="suggestion_1_281022">FAVER-DYKES <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281025:-85.2133333:30.8088889::FL", "281025", 1 )" id="suggestion_1_281025">FLORIDA CAVERNS <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281027:-81.4347222:30.67::FL", "281027", 1 )" id="suggestion_1_281027">FORT CLINCH <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("NE:230077:-103.4941667:42.6866667::NE", "230077", 1 )" id="suggestion_1_230077">Fort Robinson <strong>SP</strong> <span>, NE</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120209:-121.5013889:36.7608333::CA", "120209", 1 )" id="suggestion_1_120209">FREMONT PEAK <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281033:-86.1566667:30.3294444::FL", "281033", 1 )" id="suggestion_1_281033">GRAYTON BEACH <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281186:-86.4466667:30.3852778::FL", "281186", 1 )" id="suggestion_1_281186">HENDERSON BEACH <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("CA:120040:-123.485:39.085::CA", "120040", 1 )" id="suggestion_1_120040">HENDY WOODS <strong>SP</strong> <span>, CA</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281036:-81.5305556:27.4711111::FL", "281036", 1 )" id="suggestion_1_281036">HIGHLANDS HAMMOCK <strong>SP</strong> <span>, FL</span></a> </div>
<div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress("FL:281037:-82.2269444:28.1430556::FL", "281037", 1 )" id="suggestion_1_281037">HILLSBOROUGH RIVER <strong>SP</strong> <span>, FL</span></a> </div>
</div>
更接近Rails handles this issue的方式。我建议你看看Rails代码,因为它还处理你引用的简单案例的一些变化。例如,您将如何处理名称间隔控制器"custom_controller".gsub(/_*([a-z]+)/i) {$1.capitalize}
?
答案 2 :(得分:0)
所需的结果只是源字符串的驼峰表示。您可以尝试使用'custom_controller'.camelize
。
答案 3 :(得分:0)