# Clean URL from two text fields

**URL:** <https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412>\
**Category:** Rails\
**Created:** [November 9, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412 "2006-11-09T19:02:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [November 9, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412/1 "2006-11-09T19:02:54Z")

</div>

I have two text fields, first name and last name, that I would like to  
use as the permalink rather than the ID. How would I combine those two  
fields to become the permalink? I’ve come across tutorials on how to  
make one field become the permalink, but not two.  
I’m using Edge rails with REST routes.

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [November 9, 2006, 8:16pm UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412/2 "2006-11-09T20:16:05Z")

</div>

That’s pretty rough.  
Probably what I would do is in routes:

map.namelink '/people/names/:first\_name/:last\_name

then in your controller you could do

User.find\_by\_full\_name(params[:first\_name], params[:last\_name])

And set up that method in your users model.  
Hope this helps!  
Jason

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [November 9, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412/3 "2006-11-09T22:18:53Z")

</div>

Jason N. wrote:

> That’s pretty rough.  
> Probably what I would do is in routes:
> 
> map.namelink '/people/names/:first\_name/:last\_name
> 
> then in your controller you could do
> 
> User.find\_by\_full\_name(params[:first\_name], params[:last\_name])
> 
> And set up that method in your users model.  
> Hope this helps!  
> Jason

Thanks for the suggestion! What I would really like is for the URL to be  
[myapp.com/people/john\_doe;edit](http://myapp.com/people/john_doe;edit)

Maybe a hidden text field (full\_name) that get’s populated by combining  
first\_name and last\_name? I wonder if this is possible …

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [November 10, 2006, 7:36am UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412/4 "2006-11-10T07:36:31Z")

</div>

Thank you for your suggestion! Since I’m using REST routes I’d like to  
keep the controller as clean as possible so I’m going to go ahead and  
stick with integer urls.

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [November 9, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/clean-url-from-two-text-fields/75412/5 "2006-11-09T22:46:40Z")

</div>

That was what I was thinking originally. It would still be OK, but  
you’ll have to split the name in your controller i.e.

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

then in PeopleController.rb I would do

before\_filter :split\_name, :only =\> [‘edit’, ‘view’, etc…]

protected

def split\_name  
@first\_name, @last\_name = params[:name].split(“\_”)  
end

Something like that should work. Then just use your first and last names  
to User.find
