2011-09-08 7 views
30

필자의 레일즈 콘솔에서 Pry 보석을 사용하고 있지만, 레일이 콘솔로되어있어 재 장전을 잃어 버린 것 같습니다! 모델 및 물건을 다시로드하는 방법. 나는 놀리려는 콘솔새로 고침하는 방법을 지루하게하십시오?

c:\rails\app> pry -r ./config/environment 

당신이 ./config/environment을 의미합니까

+0

감사에서 촬영, 모두! –

답변

1

감사를 시작하는 방법은 다음과

이야?

어쨌든, 실제로는 레일 콘솔을 실행하는 것과 다릅니다. reload!의 출처는 여기에 있습니다. 나는 전체 콘솔을 보장하는 내 env 특정 설정 파일에 IRB = Pry을 재정의하고, 모두 매력처럼 작동한다.

2

최근에 저금리 및 난간에 대한 게시물을 작성했습니다. 여기서 찾을 수 있습니다 http://lucapette.com/pry/pry-everywhere/. 데이브는 이미 말했듯이 그건 그렇고, 당신은 함께 놀리려는를 사용하고 싶습니다 :

pry -r ./config/environment 

나는, 정말 잘 작동 내가 기사에 쓴 시도 할 것을 권장합니다.

+0

프로덕션 환경에서 사용하기 위해'RAILS_ENV = production pry -r./config/environment'를 사용할 수 있습니다. –

6

당신은 당신의 레일 환경을로드 할 캐내다을 말할 수있는 당신의 .pryrc

rails = File.join Dir.getwd, 'config', 'environment.rb' 

if File.exist?(rails) && ENV['SKIP_RAILS'].nil? 
    require rails 

    if Rails.version[0..0] == "2" 
    require 'console_app' 
    require 'console_with_helpers' 
    elsif Rails.version[0..0] == "3" 
    require 'rails/console/app' 
    require 'rails/console/helpers' 
    else 
    warn "[WARN] cannot load Rails console commands (Not on Rails2 or Rails3?)" 
    end 
end 

이것은 당신의 reload! 등을 제공 할 것입니다.

+0

감사합니다 Netmute, 이것은 지금까지 내가 볼 수있는 것에서 가장 잘 작동합니다. –

+1

아아, 다시로드하십시오! 실제로 작동하는 것으로 보이지만 실제로 모델을 다시로드하지 않았습니다. 그러나, Banister의 답변에서 플러그인은 그것을 할 것으로 보인다 레일 3.2에서 –

+2

나는 또한'Rails :: ConsoleMethods'를 포함해야한다고 말해야했다 – Peter

2
alias pryr="pry -r ./config/environment -r rails/console/app -r rails/console/helpers" 
12

: 그들은 이전 버전에서 IRB 명령 Object에 방법으로 추가 된 reload!가, 지금은 추가 구현하는 방법을 변경했기 때문에 대답은, 레일 3.2에서 변경되었습니다 전역 이름 공간을 오염시키지 않으려면 IRB::ExtendCommandBundle으로 변경하십시오.

내가 지금 할 것은 (1) development.rb에서

silence_warnings do 
    begin 
    require 'pry' 
    IRB = Pry 
    module Pry::RailsCommands ;end 
    IRB::ExtendCommandBundle = Pry::RailsCommands 
    rescue LoadError 
    end 
end 

(2) .pryrc에서

if Kernel.const_defined?("Rails") then 
    require File.join(Rails.root,"config","environment") 
    require 'rails/console/app' 
    require 'rails/console/helpers' 
    Pry::RailsCommands.instance_methods.each do |name| 
    Pry::Commands.command name.to_s do 
     Class.new.extend(Pry::RailsCommands).send(name) 
    end 
    end 
end 

여기에 레일에 대한 링크가 변경이 도입 된 요청을 당겨입니다 - https://github.com/rails/rails/pull/3509

+2

pry-rails는 레일과 함께 작동한다 3.2 – tee

15

reload! 레일 콘솔 명령처럼, 당신의 .pryrc에

# load Rails Console helpers like reload 
require 'rails/console/app' 
extend Rails::ConsoleMethods 
puts 'Rails Console Helpers loaded' 

편집 == 보석 놀리려는 레일을이 코드를 추가 이미이 훨씬 더 간단의 모든 작업을 수행 할 수 있습니다.당신이 제우스와 들어 올립니다에 문제가있는 경우

+0

gem "설치하다"물론 설치됨 –

2

, 당신의 .pryrc에 추가하려고 :

if Kernel.const_defined?(:Rails) && Rails.env 
    require File.join(Rails.root,"config","environment") 
    require 'rails/console/app' 
    require 'rails/console/helpers' 
    extend Rails::ConsoleMethods 
end 

here

관련 문제