Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
First argument in form cannot be nil error
<div class="content pad10">
<%= form_for @department do |f| %>
<p>
<%= f.label :department, 'Department Name' %>
<%= f.text_field 'department' %>
</p>
<p>
<%= f.label :parent %>
<% department_array = @departments.all.map { |department| [department.name, department.id + 1] } %>
<%= f.select :parent, options_for_select(department_array) %>
</p>
<%= f.submit 'Add Department', class: 'btn-std' %>
<% end %>
</div>
class DashboardController < ApplicationController
before_action :require_login
before_filter :init
def index
@departments.each do |department|
childfetch = Department.where(parent: "#{department.name}").select('name')
instance_variable_set("@#{department.name}Children".gsub(' ','_'), childfetch.map { |child| "#{child.name}" }.join(',') )
end
end
def office
end
def preferences
end
def company
end
private
def require_login
unless session[:user_id].present?
redirect_to root_url
end
end
def init
@current_user = session[:user_id]
@departments = Department.where(parent: '')
end
end
class DepartmentController < ApplicationController
def index
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.