Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Company create form and company show
- Loading branch information
1 parent
9516e39
commit 509220d
Showing
7 changed files
with
52 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
class CompaniesController < ApplicationController | ||
|
||
def new | ||
@company = Company.new | ||
@company.employees.build | ||
end | ||
|
||
def create | ||
@company = Company.new(params[:company]) | ||
if @company.save | ||
flash[:success] = "Company created successfully." | ||
redirect_to @company | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
@company = Company.find(params[:id]) | ||
@employees = @company.employees | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class Company < ActiveRecord::Base | ||
attr_accessible :description, :name | ||
attr_accessible :description, :name, :employees_attributes | ||
has_many :employments, as: :employmentable | ||
has_many :employees, through: :employments | ||
|
||
accepts_nested_attributes_for :employees, :reject_if => proc { |employee| employee['email'].blank? || employee['password'].blank? || employee['password_confirmation'].blank? } | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
h1 "Hello World" | ||
h1 Hello World | ||
|
||
= form_for @company do |f| | ||
-if @company.errors.any? | ||
- if @company.errors.any? | ||
div.error_messages | ||
h2 Form is invalid | ||
ul | ||
- for message in @company.errors.full_messages | ||
li = message | ||
|
||
= f.fields_for :employees do |builder| | ||
h3 Company Moderator | ||
|
||
f.fields_for :employees, @company.employees do |builder| | ||
builder.label :name | ||
builder.text_field :name | ||
= builder.label :email | ||
= builder.text_field :email | ||
|
||
builder.label :email | ||
builder.text_field :email | ||
= builder.label :password | ||
= builder.password_field :password | ||
|
||
builder.label :password | ||
builder.password_field :password | ||
= builder.label :password_confirmation | ||
= builder.password_field :password_confirmation | ||
|
||
builder.label :password_confirmation | ||
builder.password_field :password_confirmation | ||
h3 Company Info | ||
|
||
f.label :name | ||
f.text_field :name | ||
= f.label :name | ||
= f.text_field :name | ||
|
||
f.label :name | ||
f.text_field :name | ||
= f.label :description | ||
= f.text_field :description | ||
|
||
f.label :name | ||
f.text_field :name | ||
= f.submit "Submit" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
h1 Shark Week? | ||
|
||
h3 Company | ||
= @company.name | ||
br | ||
h3 Description | ||
= @company.description | ||
br | ||
h3 Employees | ||
- @employees.each do |employee| | ||
= employee.email |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RenameUserIdToEmployeeId < ActiveRecord::Migration | ||
def change | ||
rename_column :employments, :user_id, :employee_id | ||
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