# Routing and forms

**URL:** <https://www.ruby-forum.com/t/routing-and-forms/49687>\
**Category:** Rails\
**Created:** [December 7, 2005, 5:44pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687 "2005-12-07T17:44:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 5:44pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/1 "2005-12-07T17:44:44Z")

</div>

please can some one explain how to solve this problem …

how do you route the http get data from a form currently it produces a  
url like this \> [http://10.1.0.10/admin/view/7?number=1](http://10.1.0.10/admin/view/7?number=1)

i would like it be like this \> [http://10.1.0.10/admin/view/7/1](http://10.1.0.10/admin/view/7/1)  
how could i do this ?

andrew

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 6:32pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/2 "2005-12-07T18:32:54Z")

</div>

Add to your routes

map.connect “:controller/:action/:id/:number”, :controller =\> ‘admin’,  
:action  
=\> ‘view’, :id =\> /^\d+$/, :number =\> /^\d+$/

Kent.

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 6:46pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/3 "2005-12-07T18:46:51Z")

</div>

ksruby wrote:

> Add to your routes
> 
> map.connect “:controller/:action/:id/:number”, :controller =\> ‘admin’,  
> :action  
> =\> ‘view’, :id =\> /^\d+$/, :number =\> /^\d+$/
> 
> Kent.

thanks that’s solved part of the problem i can now enter the url  
manualy

the thing forgot to say was that im trying to use a dropdown box on a  
form to the generate the url ie you select the item number for the  
drop down but when i submit the form i would like the url to come out as  
:controller/:action/:id/:number([http://10.1.0.10/admin/view/7/2](http://10.1.0.10/admin/view/7/2)) but  
it come up as [http://10.1.0.10/admin/view/7/1?number=2](http://10.1.0.10/admin/view/7/1?number=2)

any idea’s how to sovle that bit?

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 7:09pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/4 "2005-12-07T19:09:37Z")

</div>

I don’t know how your form looks like, but if you have this rule in your  
routes

map.connect ‘admin/view/:id/:number’, :controller =\> ‘admin’, :action =\>  
‘view’, :id =\> /^\d+$/, :number =\> /^\d+$/

then

\<%= url\_for :controller =\> ‘admin’, :action =\> ‘view’, :id =\> 3, :number  
=\> 4  
%\>

generates

[http://your-site/admin/view/3/4](http://your-site/admin/view/3/4)

Kent.

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 7:34pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/5 "2005-12-07T19:34:10Z")

</div>

Well, in this case form\_tag method’s already generated the url for the  
submit  
action. It doesn’t know about the :number part. So in this case Rails  
can’t  
help you, it’s your browser that appends ?number= query parameter. You  
can  
change form action with javascript though.

Kent.

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 7:22pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/6 "2005-12-07T19:22:32Z")

</div>

ksruby wrote:

> I don’t know how your form looks like, but if you have this rule in your  
> routes
> 
> map.connect ‘admin/view/:id/:number’, :controller =\> ‘admin’, :action =\>  
> ‘view’, :id =\> /^\d+$/, :number =\> /^\d+$/
> 
> then
> 
> \<%= url\_for :controller =\> ‘admin’, :action =\> ‘view’, :id =\> 3, :number  
> =\> 4  
> %\>
> 
> generates
> 
> [http://your-site/admin/view/3/4](http://your-site/admin/view/3/4)
> 
> Kent.

if it’s any help here’s the code for the form :

\<%= form\_tag({ :action =\> “view”, :id =\> @chapter.fanfics\_id },{:method  
=\>“get”,:name =\>“form1”}) %\>

\<%=options\_from\_collection\_for\_select(@menu, "number", "title", selected\_value =[@chapter.number,@chapter.title]) %\> \<%= end\_form\_tag %\>

and the controller :  
def view  
id = ((params[:id]))  
num = @params[“number”]  
if num == nil  
num = 1  
else  
end  
@number=num

@chapter = Chapter.find\_by\_fanfics\_id\_and\_number((params[:id]),num)

@menu = Chapter.find\_by\_sql [" SELECT \* FROM chapters WHERE fanfics\_id  
= ?",id]

end  
end

---

<div class="post-metadata">

**Author:** ![mad4dos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@mad4dos](https://www.ruby-forum.com/u/mad4dos)\
**Post date:** [December 7, 2005, 7:43pm UTC](https://www.ruby-forum.com/t/routing-and-forms/49687/7 "2005-12-07T19:43:12Z")

</div>

ksruby wrote:

> Well, in this case form\_tag method’s already generated the url for the  
> submit  
> action. It doesn’t know about the :number part. So in this case Rails  
> can’t  
> help you, it’s your browser that appends ?number= query parameter. You  
> can  
> change form action with javascript though.
> 
> Kent.

ok thanks any way

is there any way of getting the same effect with out useing forms  
or would it be best to replace the dropdown box with a row of  
hyperlinks
