Last active
August 29, 2015 14:12
-
-
Save josephrexme/1fe8183cadfc573e0030 to your computer and use it in GitHub Desktop.
First argument in form cannot be nil error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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