Overloaded view / model code

This is getting perhaps a little too complex for my mind to handle.

What I'm trying to accomplish is to generate a list of of hosts which are clickable links from my related Person model.

Person # return an array with links   def hostlist_linked     if self.host == nil then       results =     else       results = self.host.sort {|a,b| a <=> b }.collect { |host| "link_to " + Setting[:base_url] + "/hosts/" + host + ", " + host + "<br>" }

    end     return results   end

and my view code has this... <%= (@person.hostlist_linked.each do |host| host; end).to_s.html_safe %>

but that doesn't actually give me links and just outputs the URL as text and the link_to doesn't actually function.

Is this possible?

The link_to must be executed as ruby, which your code makes no attempt to do. Much easier just to put the urls in the collection then do the link_to in the loop, something like <% @person.hostlist_linked.each do |host| %>   <%= link_to host %> <% end %>

Colin

This is getting perhaps a little too complex for my mind to handle.

What I'm trying to accomplish is to generate a list of of hosts which are clickable links from my related Person model.

Person # return an array with links def hostlist_linked    if self.host == nil then      results =    else      results = self.host.sort {|a,b| a <=> b }.collect { |host| "link_to " + Setting[:base_url] + "/hosts/" + host + ", " + host + "<br>" }

   end    return results end

and my view code has this... <%= (@person.hostlist_linked.each do |host| host; end).to_s.html_safe %>

but that doesn't actually give me links and just outputs the URL as text and the link_to doesn't actually function.

The link_to must be executed as ruby, which your code makes no attempt to do. Much easier just to put the urls in the collection then do the link_to in the loop, something like <% @person.hostlist_linked.each do |host| %> <%= link_to host %> <% end %>