# Link\_to: Space in between 2 variables used for anchor

**URL:** <https://www.ruby-forum.com/t/link-to-space-in-between-2-variables-used-for-anchor/110710>\
**Category:** Rails\
**Created:** [July 30, 2007, 2:54am UTC](https://www.ruby-forum.com/t/link-to-space-in-between-2-variables-used-for-anchor/110710 "2007-07-30T02:54:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eboss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@eboss](https://www.ruby-forum.com/u/eboss)\
**Post date:** [July 30, 2007, 2:54am UTC](https://www.ruby-forum.com/t/link-to-space-in-between-2-variables-used-for-anchor/110710/1 "2007-07-30T02:54:24Z")

</div>

I have this code to create a link

**Employee:** \<%= link\_to({@employee.first\_name,  
@employee.last\_name}, :controller =\> ‘employees’, :action =\> ‘show’, :id  
=\> @employee.id) %\>

It created a link with the anchor text of “FirstLast”. How do I put a  
space in between the two so it looks like “First L.”?

---

<div class="post-metadata">

**Author:** ![eboss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@eboss](https://www.ruby-forum.com/u/eboss)\
**Post date:** [July 30, 2007, 4:24am UTC](https://www.ruby-forum.com/t/link-to-space-in-between-2-variables-used-for-anchor/110710/2 "2007-07-30T04:24:58Z")

</div>

Jeremy L. wrote:

> I have this code to create a link
> 
> **Employee:** \<%= link\_to({@employee.first\_name,  
> @employee.last\_name}, :controller =\> ‘employees’, :action =\> ‘show’, :id  
> =\> @employee.id) %\>
> 
> It created a link with the anchor text of “FirstLast”. How do I put a  
> space in between the two so it looks like “First L.”?

Do one of the following things.

# Add a full\_name method to your Employee model

# Add a helper to render the full name

I prefer the first option…

class Employee

# … etc

def full\_name  
first\_name + ’ ’ last\_name  
end  
end

Then you get… @employee.full\_name in your code.

\<%= link\_to( @employee.full\_name, :controller =\> … ) %\>

The helper route?

# add to a helper file that your view can access

def full\_name(employee)  
employee.first\_name + ’ ’ + employee.last\_name  
end

\<%= link\_to( full\_name(@employee), :controller =\> … ) %\>

Either of those should work for you. I prefer to see something like this  
in the model.

Cheers,  
Robby

–  
Robby R.  
[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

---

<div class="post-metadata">

**Author:** ![eboss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@eboss](https://www.ruby-forum.com/u/eboss)\
**Post date:** [July 31, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/link-to-space-in-between-2-variables-used-for-anchor/110710/3 "2007-07-31T19:30:21Z")

</div>

Em Domingo 29 Julho 2007 23:24, Robby R. escreveu:

> Do one of the following things.
> 
> # Add a full\_name method to your Employee model
> 
> # Add a helper to render the full name

[…]

Can’t I do the follow?

\<%= link\_to("#{employee.first name} #{employee.last\_name}", :controller  
=\> ‘employees’, :action =\> ‘show’, :id =\> @employee.id) %\>

Thanks

## – Davi V. removed\_email\_address@domain.invalid removed\_email\_address@domain.invalid
