I want to use scratch files as a console replacement for prototyping in my Rails apps. The simplest solution I've found is requiring environment manually like this:
require '/project/path/config/environment.rb'
But it does not use Spring and is terribly slow because of that.
I've found two ways to do it, depending on your workflow one might fit you better than another. Assuming you're using IDEA 14 (it might be different for earlier versions) and Rails 4.1+.
Run -> Edit Configurations...
;<Path to your bin/rails file>
;runner <Path to your script>
;<Your project dir>
;RAILS_ENV=development
;-e '$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)'
;<Your project SDK>
. <check>
.The problem with this approach is that you would have to manually change path to scratch file each time you want to run the different one (please comment if you know workaround).
Assuming you have Spring installed:
IntelliJ IDEA -> Preferences
; Tools -> External Tools
; +
in the bottom of the menu:Rails Runner
;$ProjectFileDir$/bin/spring
;rails runner $FilePath$
;$ProjectFileDir$
. Keymap
:Rails Runner
;Alt + S
is convenient and available). The only problem with this approach is that you have to have custom shortcut to make it convenient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With