# Inconsistent routing

**URL:** <https://www.ruby-forum.com/t/inconsistent-routing/129818>\
**Category:** Radiant CMS\
**Created:** [February 21, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818 "2008-02-21T20:01:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/1 "2008-02-21T20:01:14Z")

</div>

Hi list,

I’m getting some weird routing issues.  
My extension defines two routes to send requests to a new controller.  
It looks like these routes are only recognized about half of the time  
(at random).  
The other times the url is just sent to the site\_controller for ‘normal’  
processing.

I guess this means that my laptop is too slow half of the time, and that  
the extra routes are not set fast enough…?

It doesn’t seem to matter if i move the extension to the front or the  
end of the extension load\_order.

Anybody have a clue of what could cause or even better fix this?

Thanks in advance,

Benny

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/2 "2008-02-21T20:13:32Z")

</div>

Benny,

Would you paste us the route definitions?

Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/3 "2008-02-21T20:26:13Z")

</div>

;  
define\_routes do |map|  
map.connect “en/shop/:action/:id”, :controller =\> ‘shop’, :language  
=\> ‘en-US’  
map.connect “nl/shop/:action/:id”, :controller =\> ‘shop’, :language  
=\> ‘nl-BE’  
end

Sean C. wrote:

> Benny,
> 
> Would you paste us the route definitions?
> 
> Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/4 "2008-02-21T20:44:21Z")

</div>

Benny,

Try this:

define\_routes do |map|  
map.with\_options :controller =\> ‘shop’, :action =\> ‘index’ do |shop|  
shop.connect “en/shop/:action/:id”, :language =\> ‘en-US’  
shop.connect “nl/shop/:action/:id”, :language =\> ‘nl-BE’  
end  
end

My guess is that without the “default” action of ‘index’, it doesn’t  
match. You can test these in a functional test:

def test\_shop\_routing\_with\_language  
assert\_recognizes “/en/shop”, :controller =\> “shop”, :action =\>  
“index”, :language =\> ‘en-US’  
assert\_recognizes “/nl/shop”, :controller =\> “shop”, :action =\>  
“index”, :language =\> ‘nl-BE’

# etc…

end

Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/5 "2008-02-21T23:08:50Z")

</div>

Nope, i’m still getting the same results; sometimes works, sometimes  
doesn’t.

the assert\_recognizes didn’t seem to work that way, i had to switch the  
first part (’/en/shop’) and the options to get those to pass

Sean C. wrote:

> Benny,
> 
> Try this:
> 
> define\_routes do |map|  
> map.with\_options :controller =\> ‘shop’, :action =\> ‘index’ do |shop|  
> shop.connect “en/shop/:action/:id”, :language =\> ‘en-US’  
> shop.connect “nl/shop/:action/:id”, :language =\> ‘nl-BE’  
> end  
> end

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 11:28pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/6 "2008-02-21T23:28:11Z")

</div>

Benny,

Ah, sorry. You might try assert\_routing, which does both a generation  
and a recognition assertion. Now, I don’t know if it has anything to do  
with your problem, but I have found that it’s more reliable to use named  
or resource routes in extensions. I’m not sure if this is a Radiant  
issue or a Rails issue. Try naming those and see if it becomes more  
consistent.

Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 21, 2008, 11:24pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/7 "2008-02-21T23:24:38Z")

</div>

> I’m getting some weird routing issues.  
> My extension defines two routes to send requests to a new controller.  
> It looks like these routes are only recognized about half of the time  
> (at random).  
> The other times the url is just sent to the site\_controller  
> for ‘normal’  
> processing.

Do you have multiple mongrel/fcgi processes? Is it possible that you  
haven’t restarted both of them? (and hence one may not have  
read your code).

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 12:11am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/8 "2008-02-22T00:11:05Z")

</div>

Are you using trunk or a previous version? This bug may have been  
introduced in the extension-loading refactoring.

Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 12:03am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/9 "2008-02-22T00:03:44Z")

</div>

assert\_routing works indeed. The test passes, but i’m still getting the  
same results:

> > app.get(’/en/shop’)  
> > =\> 302
> 
> > app.get(’/en/shop’)  
> > =\> 200
> 
> > app.get(’/en/shop’)  
> > =\> 302
> 
> > app.get(’/en/shop’)  
> > =\> 200
> 
> > app.get(’/en/shop’)  
> > =\> 302
> 
> > app.get(’/en/shop’)  
> > =\> 200
> 
> > app.get(’/en/shop’)  
> > =\> 200
> 
> > app.get(’/en/shop’)  
> > =\> 200

This is with a named route.

Daniel; as far as i know i’m not working with multiple mongrel  
processes. I’m still working in development mode only, and i haven’t  
played with setting up mongrel clusters or anything…

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 12:16am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/10 "2008-02-22T00:16:22Z")

</div>

Ah. Try freezing to revision 679:

rake radiant:freeze:edge REVISION=679

Sean

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 12:27am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/11 "2008-02-22T00:27:35Z")

</div>

Hey all,

I’m building a rake task to pull all my data from my production db  
(MySql) to my development db (SQLite). It works great pulling in that  
direction, but when I go to reverse the process, it fails. It has to  
do with my plugin that uses attachment\_fu.

Basically, I have a model Asset that uses ‘has\_attachment’. This is  
the code that doesn’t work:

“asset”.classify.constantize

This is the error:  
NoMethodError: undefined method `has\_attachment’ for Asset:Class

Any ideas what the difference is between production and development  
that would cause this to not work? I can run the server in dev mode,  
I just can’t run constantize. This error does _not_ happen in the  
production environment. I’ve tried changing the contents of config/  
environments/development.rb with no success.

Thanks!

-Chris

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 12:12am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/12 "2008-02-22T00:12:23Z")

</div>

Sean C. wrote:

> Are you using trunk or a previous version? This bug may have been  
> introduced in the extension-loading refactoring.
> 
> Sean

I’m on 0.6.4, running from gem

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 1:29am UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/13 "2008-02-22T01:29:05Z")

</div>

Sean C. wrote:

> Ah. Try freezing to revision 679:
> 
> rake radiant:freeze:edge REVISION=679
> 
> Sean

freezing didn’t solve the problem, but i’ve found out more about it…  
Turning off another extension, i noticed that i had good results more  
often.  
I then tried the extension on the production server, and it all works  
flawless there…  
maybe it’s time for a reboot… 🙂

---

<div class="post-metadata">

**Author:** ![jomz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jomz](https://www.ruby-forum.com/u/jomz)\
**Post date:** [February 22, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/inconsistent-routing/129818/14 "2008-02-22T18:45:12Z")

</div>

Nevermind, I must have had something wacky in my config. I started  
fresh with a new 0.6.4 install and brought in my extension, and it  
seems fine now. Sorry for the noise on the channel…

-C
