I have following code which seems to work fine:
<%if group.employees.count > 0%>
<td><%= link_to group.employees.count.to_s, {:action => 'index', :controller => 'employees'}, {:id=>group.id}%></td>
<%else%>
<td><%= link_to "Add Employee", {:action => 'new', :controller => 'employees'}%></td>
<%end%>
I’m just wondering how this can be written in more rails friendly way using unless?
I would (with dylanfm’s advice in the comment underneath) write it like this:
Here I’ve used the
employees_pathandnew_employee_pathmethods which are generated by using the routing helpers in config/routes.rb. You can read more about routing by reading the Routing from the Outside In guide.