Created
December 24, 2014 06:32
-
-
Save josephrexme/fac338e1d1c4b2d1f4cc to your computer and use it in GitHub Desktop.
Displaying various form create on a page
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
<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> |
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 | |
@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 |
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 | |
def create | |
@department = Department.new(params[:department]) | |
end | |
def edit | |
end | |
def update | |
end | |
def destroy | |
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
No route matches [POST] "/dashboard/department_path" | |
(The `new` page for department creation is in dashboard/company as shown in the routes.rb) |
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
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