Testing Rails Routes in the Console
[
]
I’ve found myself trying to test as quickly as possible if I have a Rails route working properly and typically turn to the console, expecting it to load all the relevant routes, but run into an error like this:
Loading backup environment (Rails 4.2.11.1)
irb(main):001:0> root_path
Traceback (most recent call last):
8: from bin/rails:4:in `<main>'
7: from bin/rails:4:in `require'
6: from /Users/Kasim/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands.rb:17:in `<top (required)>'
5: from /Users/Kasim/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
4: from /Users/Kasim/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/commands_tasks.rb:68:in `console'
3: from /Users/Kasim/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/console.rb:9:in `start'
2: from /Users/Kasim/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/console.rb:110:in `start'
1: from (irb):1
NameError (undefined local variable or method `root_path' for main:Object)
irb(main):002:0>
Since I’m running this locally, I expect this to return localhost:4000
. It turns out that all the routes are included under the app
object, so instead I have to do this:
irb(main):004:0> app.root_url
=> "http://localhost:3000/"
irb(main):005:0>
More
Archive
chinese
tang-dynasty-poetry
李白
python
王维
rl
pytorch
numpy
emacs
杜牧
spinningup
networking
deep-learning
贺知章
白居易
王昌龄
杜甫
李商隐
tips
reinforcement-learning
macports
jekyll
骆宾王
贾岛
孟浩然
xcode
time-series
terminal
regression
rails
productivity
pandas
math
macosx
lesson-plan
helicopters
flying
fastai
conceptual-learning
command-line
bro
黄巢
韦应物
陈子昂
王翰
王之涣
柳宗元
杜秋娘
李绅
张继
孟郊
刘禹锡
元稹
youtube
visdom
system
sungho
stylelint
stripe
softmax
siri
sgd
scipy
scikit-learn
scikit
safari
research
qtran
qoe
qmix
pyhton
poetry
pedagogy
papers
paper-review
optimization
openssl
openmpi
nyc
node
neural-net
multiprocessing
mpi
morl
ml
mdp
marl
mandarin
macos
machine-learning
latex
language-learning
khan-academy
jupyter-notebooks
ios-programming
intuition
homebrew
hacking
google-cloud
github
flashcards
faker
docker
dme
deepmind
dec-pomdp
data-wrangling
craftsman
congestion-control
coding
books
book-review
atari
anki
analogy
3brown1blue
2fa