I have a controller:
class UsersController < ApplicationController
def departments
@users_departments = current_user.departments
@new_department = current_user.department.new
end
My view looks similar like this:
<%= form_for @new_department, :url => {:action => "departments"} do |f| %>
.
<% end %>
<% @users_departments.each do |dept| %>
<td><%= dept.name %></td>
<td><%= dept.employees %></td>
<% end %>
@users_departments.each... shows me an empty department. Why? And how to solve that?
First of all - try to use REST form_for doc
something like that:
will generate link to create action in your UserController
And about @users_departments.each - maybe in your DB current_user.departments.count - return 0
I mean maybe there is no such record in your database.