2015-01-14 39 views

回答

3

我通常做到以下幾點:

cd `bundle show rails` # Go to the directory having rails gem content 
cd ..     # Go one level up to the folder having all gems 
grep -ir escape_javascript * # search for the required text in all files 
> actionview-4.1.6/lib/action_view/helpers/javascript_helper.rb:  def escape_javascript(javascript) 
> actionview-4.1.6/lib/action_view/helpers/javascript_helper.rb:  alias_method :j, :escape_javascript 

編輯:由jrochkind下面的答案是正確的答案;我的答案不正確,因爲它搜索系統中安裝的所有gem。

+0

'grep的-ir escape_javascript *'' 的grep:*:沒有這樣的文件或directory' – Rodrigo

+1

'沒有這樣的文件或directory'會因爲一些不可讀/不存在的文件;通過傳遞'-s'來修復http://stackoverflow.com/a/16297914/429758; 'grep -isr escape_javascript *'。 bundle文件夾不應該有這個問題,因爲它沒有任何符號鏈接。 –

+0

它運作普拉卡什。但我的rails gem目錄是空的。你知道爲什麼嗎? – Rodrigo

8

接受的答案將搜索全部安裝在系統上的gem,可能包括那些實際上並不依賴的gem。

要搜索只有通過您的應用程序的實際依賴關係,不是任何安裝的寶石,從應用程序根目錄:

grep -r "escape_javascript" $(bundle show --paths) . 

在年底.將確保搜索您的實際應用過,不是只有它是依賴關係。如果那是你想要的。

http://hectorcorrea.com/blog/bundle-grep-and-rails-applications/68

+0

使用https://github.com/ggreer/the_silver_searcher: 'ag i_search_for_escape_javascript --ruby \'bundle show --paths \'' – jmgarnier

相關問題