Clean URL from two text fields

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.

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

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

Maybe a hidden text field (full_name) that get’s populated by combining
first_name and last_name? I wonder if this is possible …

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.

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.

myapp.com/people/john_doe/edit

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs