Link_to: Space in between 2 variables used for anchor

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.”?

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/

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.
[email protected]
[email protected]