Forum: Ruby on Rails Console for Testing Routes?

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.
3504745159d79c585e4f7df8df76aa10?d=identicon&s=25 Ingo Weiss (ingoweiss)
on 2006-04-04 16:06
Hi,

when the "Agile Web Development" book talks about routes, there are what
looks like console transcripts like the following:

URL> store
@params = {:controller => 'store', :action = 'index'}

Is there something like a console for testing routes (where you could
put in a url and see how rails would route it)??

Ingo
Df040ca3576504b24a73744179903277?d=identicon&s=25 Tobias Lütke (Guest)
on 2006-04-04 18:19
(Received via mailing list)
I'm pretty sure that dave just created that for demonstration purposes
but the latest rails as the app object in the console which you can
use for this:

./script/console
>> app.url_for :controller => 'store', :action => 'index'
=> "http://www.example.com/store"
>> app.host! 'www.snowdevil.ca'
=> "www.snowdevil.ca"
>> app.url_for :controller => 'store', :action => 'index'
=> "http://www.snowdevil.ca/store"

On 4/4/06, Ingo Weiss <ingoweiss@gmail.com> wrote:
>
> Ingo
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Tobi
http://shopify.com       - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog
90842970ceaf7ed19136ce7b6f8e1455?d=identicon&s=25 Michael Daines (Guest)
on 2006-04-04 19:47
(Received via mailing list)
Is there any way to do that sort of thing from a controller? Giving
some function a path and then getting the params that path would
produce?

For example, passing this to some function:

   "/store/edit/1"

and getting back

   [:controller => "store", :action => "edit", :id => "1"]

or whatever the appropriate params for the route are.


-- Michael Daines
Df040ca3576504b24a73744179903277?d=identicon&s=25 Tobias Lütke (Guest)
on 2006-04-04 21:01
(Received via mailing list)
ruby script/console
Loading development environment.
app.get >> app.get '/'
=> 200
>> app.controller.params
=> {"action"=>"index", "controller"=>"shop"}


On 4/4/06, Michael Daines <michael.daines@gmail.com> wrote:
>
> > when the "Agile Web Development" book talks about routes, there are
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Tobi
http://shopify.com       - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog
90842970ceaf7ed19136ce7b6f8e1455?d=identicon&s=25 Michael Daines (Guest)
on 2006-04-05 02:36
(Received via mailing list)
I've seen that, which is good, but I mean from within an action in a
controller or elsewhere, not from the console.

At some point, my application gets lists of URLs, and I want to know
what params their paths produce.

(Plus, oops! Those should have been curly braces.)


-- Michael Daines


On Apr 4, 2006, at 12:00 PM, Tobias Lütke wrote:
3504745159d79c585e4f7df8df76aa10?d=identicon&s=25 Ingo Weiss (ingoweiss)
on 2006-04-05 07:32
This is great! Thanks!!

Ingo






> ruby script/console
> Loading development environment.
> app.get >> app.get '/'
> => 200
>>> app.controller.params
> => {"action"=>"index", "controller"=>"shop"}
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-05 08:40
(Received via mailing list)
Michael Daines wrote:
> I've seen that, which is good, but I mean from within an action in a
> controller or elsewhere, not from the console.
>
> At some point, my application gets lists of URLs, and I want to know
> what params their paths produce.

This might help:

http://clarkware.com/cgi/blosxom/2006/04/04#HeadlessApp

--

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