Skip to content

Instantly share code, notes, and snippets.

@josephrexme
Created December 24, 2014 06:32
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/fac338e1d1c4b2d1f4cc to your computer and use it in GitHub Desktop.
Save josephrexme/fac338e1d1c4b2d1f4cc to your computer and use it in GitHub Desktop.
Displaying various form create on a page
<section class="row-doubles">
<div>
<div class="title">Add Department</div>
<div class="content pad10">
<%= form_for @department, url: 'department_path' do |f| %>
<p>
<%= f.label :name, 'Department Name' %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :parent %>
<% department_array = @departments.all.map { |department| [department.name, department.id + 1] } %>
<%= f.select :parent, options_for_select([['no parent', 1]] + department_array) %>
</p>
<%= f.submit 'Add Department', class: 'btn-std' %>
<% end %>
</div>
</div>
<div>stuff</div>
</section>
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
@department = Department.new
end
private
def require_login
unless session[:user_id].present?
redirect_to root_url
end
end
def init
@departments = Department.where(parent: '')
end
end
class DepartmentController < ApplicationController
def index
end
def create
@department = Department.new(params[:department])
end
def edit
end
def update
end
def destroy
end
end
No route matches [POST] "/dashboard/department_path"
(The `new` page for department creation is in dashboard/company as shown in the routes.rb)
Rails.application.routes.draw do
get 'department/index'
get 'sessions/new'
get 'users/new'
get 'login' => 'sessions#new', as: :log_in
get 'logout' => 'sessions#destroy', as: :log_out
resources :sessions, :users, :staffs, :departments
get 'dashboard/user' => 'dashboard#user', as: :dashboard_user
get 'dashboard/company' => 'dashboard#company', as: :dashboard_company
get 'dashboard/preferences' => 'dashboard#preferences', as: :dashboard_setting
get 'dashboard/office' => 'dashboard#office', as: :dashboard_office
get 'dashboard' => 'dashboard#index', as: :dashboard
get 'login' => 'welcome#login'
root 'sessions#new'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment