I have this code to create a link <b>Employee:</b> <%= 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 Last"? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robby Russell
2007-Jul-30 02:24 UTC
Re: link_to: Space in between 2 variables used for anchor
Jeremy Luebke wrote:> I have this code to create a link > > <b>Employee:</b> <%= 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 Last"?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 Russell http://www.robbyonrails.com/ http://www.planetargon.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Em Domingo 29 Julho 2007 23:24, Robby Russell escreveu:> Jeremy Luebke wrote: > > I have this code to create a link > > > > <b>Employee:</b> <%= 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 Last"? > > 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 Vidal davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -- -------------------------------------------------------- Por favor não faça top-posting, coloque a sua resposta abaixo desta linha. Eu não respondo top-post/HTML post. Obrigado. Please don''t do top-posting, put your reply below the following line. I don''t reply to top-post/HTML post. Thank you. --------------------------------------------------------