Question:"no route found to match"

hi.
in my routes.rb, I have such url
map.file ':user/:file
it works well with following url:
1. jay/web
2. jay/web2
but it encounters error with: jay/web2.0
it displays : no route found to match "/post/web2.o" with
{:method=>:get}
I guess it is because the char '.' and rails can not translate it
exactly.

How can I fix it ?
thank you
zico

zico wrote:

hi.
in my routes.rb, I have such url
map.file ':user/:file
it works well with following url:
1. jay/web
2. jay/web2
but it encounters error with: jay/web2.0
it displays : no route found to match "/post/web2.o" with
{:method=>:get}
I guess it is because the char '.' and rails can not translate it
exactly.

Add this to the end of your route:

, :requirements => { :file => /.*/ }

Michael Wang
  
  thanks.it works well now.
  but if I want to user such url: jay.zhang/web2.0.
  I tried to change the route into:
   1.:user => 'all', :file => 'all' , :requirements => { :user => /.*/ } , :requirements => { :file => /.*/ }
   2.:user => 'all', :requirements => { :user => /.*/ } , :file => 'all' , :requirements => { :file => /.*/ }
  but it seems that it does not take effect.
  how to write the route in this kind of situation?
  Thanks again.

Best Regards.
Zike Zhang
2007-03-14

Zike Zhang wrote:

Michael Wang
  
  thanks.it works well now.
  but if I want to user such url: jay.zhang/web2.0.
  I tried to change the route into:
   1.:user => 'all', :file => 'all' , :requirements => { :user => /.*/ } , :requirements => { :file => /.*/ }
   2.:user => 'all', :requirements => { :user => /.*/ } , :file => 'all' , :requirements => { :file => /.*/ }
  but it seems that it does not take effect.
  how to write the route in this kind of situation?
  Thanks again.

I haven't tested it but try something like:

:requirements => { :user => /.*/, :file => /.*/ }

Michael Wang

  yes.i have tested it like , :requirements => { :user => /.*/, :file => /.*/ }
  but the link redirect to the root page automatically if i wrote :
   1.jay.zh/web2.0
   2.jay.zh

Best Regards.
Zike Zhang
2007-03-14

Zike Zhang wrote:

Michael Wang

  yes.i have tested it like , :requirements => { :user => /.*/, :file => /.*/ }
  but the link redirect to the root page automatically if i wrote :
   1.jay.zh/web2.0
   2.jay.zh

Best Regards.
Zike Zhang
2007-03-14

-------------------------------------------------------------
From:Michael Wang
Date:2007-03-14 10:09:28
To:rubyonrails-talk@googlegroups.com
Cc:
Subject:[Rails] Re: Question:"no route found to match"

Zike Zhang wrote:

Michael Wang
  
  thanks.it works well now.
  but if I want to user such url: jay.zhang/web2.0.
  I tried to change the route into:
   1.:user => 'all', :file => 'all' , :requirements => { :user => /.*/ } , :requirements => { :file => /.*/ }
   2.:user => 'all', :requirements => { :user => /.*/ } , :file => 'all' , :requirements => { :file => /.*/ }
  but it seems that it does not take effect.
  how to write the route in this kind of situation?
  Thanks again.

I haven't tested it but try something like:

:requirements => { :user => /.*/, :file => /.*/ }

I just tested it and it works for me with Rails 1.2.2.

routes.rb:

  map.connect '/:user/:file', :controller => "main", :action => "index",
:requirements => { :user => /.*/, :file => /.*/ }

views/main/index.rhtml:

<%= params[:user] -%><br/>
<%= params[:file] -%><br/>

If I input:

http://locahost:3000/john.doe/file.ext

I see in my browser:

john.doe
file.ext

Michael Wang