# Rails 3 constraints, named routes and form\_tag

**URL:** <https://www.ruby-forum.com/t/rails-3-constraints-named-routes-and-form-tag/190388>\
**Category:** Rails\
**Created:** [June 18, 2010, 11:24pm UTC](https://www.ruby-forum.com/t/rails-3-constraints-named-routes-and-form-tag/190388 "2010-06-18T23:24:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_McCann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c2a13f/32.png) [@Alan\_McCann](https://www.ruby-forum.com/u/Alan_McCann)\
**Post date:** [June 18, 2010, 11:24pm UTC](https://www.ruby-forum.com/t/rails-3-constraints-named-routes-and-form-tag/190388/1 "2010-06-18T23:24:50Z")

</div>

I have the following URL I match to show a subset of text from a book

/bookname/chapter1/line1/chapter2/line2

I have a route definition that works perfectly when entering a url in  
the browser however I cannot get a link\_to or path name for this url

match ‘/:book/:chapter1/:line1/:chapter2/:line2’,  
:to =\> “lines#showlines”,  
:constraints =\> {  
:book =\> /\d\*\s?\w{2,}/,  
:chapter1 =\> /\d+/,  
:line1 =\> /\d+/,  
:chapter2 =\> /\d+/,  
:line2 =\> /\d+/ },  
:as =\> :showlines

I keep getting the error  
No route matches  
{:chapter1=\>“1”, :verse1=\>“1”, :controller=\>“verses”, :chapter2=\>“1”,  
:action=\>“showverses”, :verse2=\>“3”, :book=\>“john”}

I have tried

\<%=h link\_to(“link”,  
showlines\_path(:book=\>‘john’,:chapter1=\>‘1’,:chapter2=\>‘1’,:line1=\>‘1’,:line2=\>‘3’))  
%\>

This is Rails 3.

Any pointers?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Alan\_McCann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c2a13f/32.png) [@Alan\_McCann](https://www.ruby-forum.com/u/Alan_McCann)\
**Post date:** [June 19, 2010, 1:17am UTC](https://www.ruby-forum.com/t/rails-3-constraints-named-routes-and-form-tag/190388/2 "2010-06-19T01:17:48Z")

</div>

FYI:

What I am trying to do is create a form to select a location in the  
book and then render it.

Thanks!

---

<div class="post-metadata">

**Author:** ![Alan\_McCann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c2a13f/32.png) [@Alan\_McCann](https://www.ruby-forum.com/u/Alan_McCann)\
**Post date:** [June 19, 2010, 7:13pm UTC](https://www.ruby-forum.com/t/rails-3-constraints-named-routes-and-form-tag/190388/3 "2010-06-19T19:13:00Z")

</div>

OK - at least I have a workaround…

removing the constraints allows link\_to, etc to work. However, I have  
to deal with checking for properly formatted URL’s in the controller.

Alan
