Forum: Ruby on Rails Restful routes and Rails Console

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D3fc5887a2f39f2e0c8989d39ce5e6f9?d=identicon&s=25 Bharat Ruparel (bruparel)
on 2009-01-28 17:10
The following is a snippet of the routes.rb file:

  map.resources :blogs do |blog|
    blog.resources :posts do |post|
        post.resources :comments
    end
  end


The index action in the CommentsController shows:

redirect_to comments_url

I am trying to see what comments_url resolves to in the Rails Console,
but do not know how.

Thanks in advance for your time and help.
978ed7ca309d5495078702096f9add03?d=identicon&s=25 Thomas r. Koll (tomk32)
on 2009-01-28 20:10
(Received via mailing list)
Hi,

On Jan 28, 5:10 pm, Bharat Ruparel wrote:

> I am trying to see what comments_url resolves to in the Rails Console,
> but do not know how.

There's a good reason for this: You don't use/need urls in your
console.
The best way is to write tests for your routes, this will also give
you the
most confidence in your own code.

ciao, tom
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2009-01-28 21:04
(Received via mailing list)
Hi--
On Jan 28, 2009, at 10:44 AM, Thomas R. Koll wrote:

> console.
> The best way is to write tests for your routes, this will also give
> you the
> most confidence in your own code.

If you want to test routes, shoulda[1] has macros for that. For rspec
users, that would be carlosbrando-remarkable[2].

If you still want to puch this stuff into console,

 >> include ActionController::UrlWriter
 >> new_session_path
=> "/session/new"

See if this helps.

[1] Projects - Shoulda
[2] carlosbrando's remarkable at master - GitHub
D3fc5887a2f39f2e0c8989d39ce5e6f9?d=identicon&s=25 Bharat Ruparel (bruparel)
on 2009-01-28 22:12
Thank you Steve.  This is precisely what I needed.
Thomas, I appreciate your time as well.  It is just that I learn better
by typing "things" in the Rails Console in bits and pieces and see what
happens.  It is this interactive nature of Ruby and Rails which I like
very much.  Reminds me of the "Immediate Window" in Visual Basic/Access
which made me very productive.

But I do agree with both you gentlemen that a structured testing
methodology is better suited for the task.

Regards,

Bharat
This topic is locked and can not be replied to.