views:

57

answers:

2

I'm using Rails script/console to learn REST routes. It is very handful!

In order to do that I need to paste these two lines every time I run console:

include ActionController::UrlWriter
default_url_options[:host] = 'whatever'

If there is any way to make a script which will add this automatically every time I run console?

+1  A: 

A bit of a hack but you could put two calls in a .rb file and require that when you start the console.

E.g.

i.rb
  include ActionController::UrlWriter
  default_url_options[:host] = 'whatever'

$ ruby script/console
>> require 'i'
Shadwell
+1  A: 

You can use the ActionController::Integration::Session object that is available at the console with the name “app”:

>> app.blog_path
=> "/blog"

One thing to note is that the app object's host name is automatically prepopulated to “www.example.com”:

>> app.host
=> "www.example.com"
>> app.blog_url
=> "http://www.example.com/blog"
pagetribe