# (simple?) routing problem

**URL:** <https://www.ruby-forum.com/t/simple-routing-problem/78802>\
**Category:** Rails\
**Created:** [December 8, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802 "2006-12-08T18:50:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/1 "2006-12-08T18:50:56Z")

</div>

Given this route:

map.connect ‘:controller/:action/:object\_name/:mailing/:check\_state’,  
:defaults =\> {:mailing =\> ‘0’, :check\_state =\> ‘0’}

and the URL spec. here (embedded in a call to remote\_function):

:url =\> {:action =\> ‘lookup\_city\_and\_state’, :object\_name =\> ‘insured’,  
:mailing =\> mailing ? ‘1’ : ‘0’, :check\_state =\> check\_state ? ‘1’ :  
‘0’}

why do I end up with this generated URL (‘artisan\_qualifiers’ is the  
name of my controller):

/artisan\_qualifiers/lookup\_city\_and\_state/insured/1

?

I would expect another / and a value for check\_state.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/2 "2006-12-08T19:04:37Z")

</div>

OK, it seems like if I remove the :defaults part of my route, then it  
works.

Did :check\_state get _completely_ ignored because the value for :mailing  
didn’t match the default value for :mailing?

I won’t use :defaults 'til I understand this.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/3 "2006-12-08T19:15:41Z")

</div>

> name of my controller):
> 
> /artisan\_qualifiers/lookup\_city\_and\_state/insured/1

In your call, what is the value of mailing and check\_state? I’d guess  
that mailing =\> 1 and check\_state =\> 0, and since that is the default,  
Rails left it off since it’s not necessary.

Be interesting to see the output of:

:url =\> {:action =\> ‘lookup\_city\_and\_state’, :object\_name =\> ‘insured’,  
:mailing =\> ‘0’, :check\_state =\> ‘1’}

and see if you get this:

/artisan\_qualifiers/lookup\_city\_and\_state/insured/0/1

-philip

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:42pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/4 "2006-12-08T19:42:08Z")

</div>

If I do what I said above, then the URL is generated as stated, but then  
in the action, params[:mailing] is nil! Why?

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/5 "2006-12-08T19:28:53Z")

</div>

Philip,

This is something that I didn’t understand about routes.

So if a value matches the default, it won’t be represented in the URL  
but the param will still get that value when the controller action is  
started, is that correct?

WG

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/6 "2006-12-08T19:53:37Z")

</div>

Alright - fuller disclosure - this is an AJAX call where I’m setting a  
query string as well.

It’s a simple ZIP code lookup action. I’m setting the params that I  
know about up front as part of the URL and using the route to get those.  
However, for the ZIP code, which comes from the form, I’m setting that  
on the query string.

Given the route above, and this call (the object\_name variable has a  
value of ‘insured’, the check\_state variable has a value of ‘0’)

\<%= text\_field(object\_name.to\_sym,  
“#{attr\_prefix}zip\_code”.to\_sym,  
:size =\> 10,  
:maxlength =\> 10,  
:onblur =\> remote\_function(:url =\> {:action =\>  
‘lookup\_city\_and\_state’,  
:object\_name =\> object\_name,  
:mailing =\> mailing ? ‘1’ :  
‘0’,  
:check\_state =\> check\_state},  
:with =\> “‘zip=’ + encodeURIComponent(this.value)”,  
:before =\> ‘ajax\_running = true; ajax\_issues =  
false’,  
:complete =\> ‘ajax\_running = false;’)) %\>

Seems like in this case - where mailing is ‘1’, check\_state is ‘0’, that  
the URL comes out as expected, but params[:object\_name],  
params[:mailing], params[:check\_state] all come in as nil.

My guess is that the presence of the query string parameter screws  
things up if the URL isn’t completely specified (which seems to happen  
based on the defaulting rule).

Weird. It’s not like the parameters in the URL and the parameters  
spec’d in the AJAX call _can’t_ coexist (they can if I don’t use  
defaults on the route).

Well, I’m back to not defaulting for this guy.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/7 "2006-12-08T20:26:23Z")

</div>

Take a look at my last post - do I need to do something in the route  
specification in order to allow for query string parameters?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/8 "2006-12-08T21:30:04Z")

</div>

That I don’t know…

would seem strange to me taht you would, but I really don’t know…

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 8:07pm UTC](https://www.ruby-forum.com/t/simple-routing-problem/78802/9 "2006-12-08T20:07:49Z")

</div>

> So if a value matches the default, it won’t be represented in the URL  
> but the param will still get that value when the controller action is  
> started, is that correct?

Could be… I was just guessing 🙂 Seems like a railish thing to do 🙂
