Skip to content

Instantly share code, notes, and snippets.

@josephrexme
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephrexme/1fe8183cadfc573e0030 to your computer and use it in GitHub Desktop.
Save josephrexme/1fe8183cadfc573e0030 to your computer and use it in GitHub Desktop.
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