---
title: "在rails console里测试routes"
author: "夜鸣猪"
date: "2012-08-10T10:19:57Z"
tags: []
categories: ["编程语言"]
slug: "rails-console-routes"
draft: false
lastmod: "2012-08-10T10:19:57Z"
id: 1627896
url: "https://hlee.iteye.com/blog/1627896"
---

Sometimes you need to check what your route helpers are returning, and the "rake routes" task isn't enough. Those helpers are accessible through an instance of the ActionController::Integration::Session class, and at the Rails console there is one instance of this class already available:



```java
>> app.class
=> ActionController::Integration::Session
>> app.users_path
=> "/users"

```
Inside the app object, the host name is automatically prepopulated to "www.example.com":

view sourceprint?

```java
>> app.host
=> "www.example.com"
>> app.users_url
=> "http://www.example.com/users"

```
You can change that host name easily:


```java
>> app.host = "evolve.st"
=> "evolve.st"
>> app.users_url
=> "http://evolve.st/users"

```
And remember: That Session instance can be used to simulate HTTP requests too. If you still didn't know about it, you should take a look at its Rails documentation page, because you will find it really interesting.