views:

458

answers:

3

I'm trying to modify the UI of a Redmine installation (Redmine 0.7.3.devel.2093 (MySQL)).

When you view a project in Redmine, it generates a list of all the subprojects for the project.

For example, app/views/projects/index.rhtml calls the link_to function:

<% if @project_tree[project].any? %>
    <p><%= l(:label_subproject_plural) %>:
    <%= @project_tree[project].sort.collect {|subproject| 
       link_to(h(subproject.name), {:action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "subp fav" : "subp"))}.join(', ') %></p>
<% end %>

Which outputs the following HTML:

<p>Subprojects:
<a href="/projects/show/foo" class="subp fav">Foo Subproject</a>, <a href="/projects/show/bar" class="subp">Bar Subproject</a>, <a href="/projects/show/baz" class="subp fav">Baz Subproject</a></p>

We find that a comma-delimited list of subprojects is very difficult to visually parse. We'd like to have each subproject listed on its own line. (Any markup is fine -- UL, OL, or P tags on each link would be ideal, but a BR instead of a comma would be totally fine.)

What is the best way to make this change? I can't find where link_to is defined in the app; grepping for def link_to( and similar turns up nothing. I'm a UI type, so I don't really get how Rails deals with this stuff -- it doesn't seem to be defined in the view templates.

+1  A: 

You can do it directly in the code you provided. Just change

join(', ')

to

join('<br />')

That should do it.

Milan Novota
A: 

link_to is provided by the Rails framework - it isn't generating the links as a list - it simply creates a single link. The issue is the sort.collect and the block generating the calls to link_to

This should work, putting the subprojects into list items

<% @project_tree[project].sort.collect do |subproject| %>
  <li>        
    <%= link_to(h(subproject.name), {:action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "subp fav" : "subp")) %>
  </li>
<% end %>
Toby Hede
+1  A: 

I wanted to point out that the latest version of Redmine trunk changed the project listing to use HTML lists (ul and li).

Eric Davis