Forum: Ruby on Rails regular expression matching in routes.rb

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.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-27 23:51
All,

I have a route specified as:

map.connect ':folder/:filename', :folder => /htmlfiles/, :controller =>
"eSimply", :action => "preview_HTML"

I expect it to invoke the "preview_HTML" action in the "eSimply"
controller.

Given an argument of "htmlfiles/xyz.html", it keeps saying that it can't
find an "htmlfiles" action.  As you can see, I'm attempting to match the
first parameter against "htmlfiles".

Any idea why this route won't match?

(I've also tried the "requirements form" of the route and can't get it
to work).

Thanks,
Wes
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-28 01:33
Wes Gamble wrote:
> All,
>
> I have a route specified as:
>
> map.connect ':folder/:filename', :folder => /htmlfiles/, :controller =>
> "eSimply", :action => "preview_HTML"
>
> I expect it to invoke the "preview_HTML" action in the "eSimply"
> controller.
>
> Given an argument of "htmlfiles/xyz.html", it keeps saying that it can't
> find an "htmlfiles" action.  As you can see, I'm attempting to match the
> first parameter against "htmlfiles".
>
> Any idea why this route won't match?

Not sure why that's not working. But routes will match literals in the
main pattern parameter, so you could just do this:

map.connect 'htmlfiles/:filename', :controller => "e_simply", :action =>
"preview_HTML"

Note that I also changed the controller to use the lowercase with
underscores form of the name, instead of the camelcase form - that might
be causing you problems too. I'm not sure of the details of how
:controller must be specified, but I always use the lowercase version
and that works for me.

--josh
Josh Susser
http://blog.hasmanythrough.com
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-28 08:22
(Received via mailing list)
Am Montag, den 27.03.2006, 23:51 +0200 schrieb Wes Gamble:
> Given an argument of "htmlfiles/xyz.html", it keeps saying that it can't
> find an "htmlfiles" action.  As you can see, I'm attempting to match the
> first parameter against "htmlfiles".
>
> Any idea why this route won't match?
>
> (I've also tried the "requirements form" of the route and can't get it
> to work).

Are you sure this route is evaluated? Perhaps a route before it is
matching and this is never processed.

--
Norman Timmler

http://blog.inlet-media.de
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-28 09:04
It's being evaluated - what is happening is that the controller is being
added to the front of the URL, when actually I don't want that to
happen.

I'm requesting the URL via a hard-coded string in Javascript so I didn't
think that the url_for stuff would happen to it, but the request itself
must be getting intercepted and modified.

In fact, I want to be able to say something like

map.connect 'xyz/abc' :controller => myController, etc.

I can't force it to ignore the controller using :controller => nil,
since that will keep it from getting evaluated correctly.

But I get the controller in front of my URL which is totally irritating
because in order to make it work I probably have to hard code the
controller name that I know will be prepended.

I think I'd like the URL generation to maybe be less smart.  I'm not
sure.

Wes

Norman Timmler wrote:
> Am Montag, den 27.03.2006, 23:51 +0200 schrieb Wes Gamble:
>> Given an argument of "htmlfiles/xyz.html", it keeps saying that it can't
>> find an "htmlfiles" action.  As you can see, I'm attempting to match the
>> first parameter against "htmlfiles".
>>
>> Any idea why this route won't match?
>>
>> (I've also tried the "requirements form" of the route and can't get it
>> to work).
>
> Are you sure this route is evaluated? Perhaps a route before it is
> matching and this is never processed.
>
> --
> Norman Timmler
>
> http://blog.inlet-media.de
This topic is locked and can not be replied to.