Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Company model #124

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@
/config/initializers/devise.rb
.DS_Store
.env

Vagrantfile
.vagrant/
hosts
playbook.yml
roles/
group_vars/
11 changes: 2 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@ gem 'devise'
gem 'omniauth-facebook'
gem 'omniauth-twitter'


# Misc
gem 'activeadmin', github: 'activeadmin/activeadmin'
gem 'acts_as_votable', '~> 0.11.0'

gem 'paperclip'
gem 'acts-as-taggable-on'
gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.0+
gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
gem 'configatron'

gem 'meetup_client'

gem 'momentjs-rails', '>= 2.9.0'

gem 'gravatar_image_tag'
gem 'owlcarousel-rails'
gem 'select2-rails'
Expand All @@ -46,14 +41,10 @@ gem 'jquery-atwho-rails'
group :development, :test do
gem 'spring'
gem 'sqlite3'

gem 'dotenv-rails'

gem 'annotate'
gem 'pry'

gem 'spring-commands-rspec'

gem 'letter_opener'

# Testing
Expand Down Expand Up @@ -85,4 +76,6 @@ end
group :development do
# benchmark performance
gem 'rack-mini-profiler'

gem 'faker'
end
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
add-event-voting
acts-as-taggable-on (3.4.4)
activerecord (>= 3.2, < 5)
acts_as_votable (0.11.0)
Expand Down Expand Up @@ -127,6 +126,8 @@ GEM
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
Expand Down Expand Up @@ -240,7 +241,6 @@ GEM
pry (0.11.1)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.0)
puma (3.10.0)
rack (1.6.8)
rack-mini-profiler (0.10.5)
Expand Down Expand Up @@ -396,6 +396,7 @@ DEPENDENCIES
devise
dotenv-rails
factory_girl_rails
faker
formulaic
friendly_id (~> 5.1.0)
fuubar
Expand Down
65 changes: 65 additions & 0 deletions app/controllers/companies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class CompaniesController < ApplicationController
before_filter :authenticate_user!, except: [:index, :show]

def index
@companies = Company.all

respond_to do |format|
format.html { @companies }
end
end

def show
@company = find_company
end

def new
@company = Company.new
end

def edit
@company = find_company
end

def create
@company = Company.new(company_params)

if @company.save
redirect_to company_path(@company)
else
render action: :new
end
end

def update
@company = find_company

if @company.update(company_params)
redirect_to company_path(@company)
else
render action: :edit
end
end

def destroy
@company = find_company

@company.destroy

redirect_to companies_path
end

private

def company_params
params.require(:company)
.permit(:name,
:logo,
:website,
:description)
end

def find_company
Company.find(params[:id])
end
end
5 changes: 5 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Company < ActiveRecord::Base
validates :name, presence: true

mount_uploader :logo, AvatarUploader
end
59 changes: 59 additions & 0 deletions app/views/companies/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<div class="section">
<div class="container">
<h1 class="section-title">
Add New Company
</h1>

<%= form_for @company, html: { class: "col-md-offset-3 col-md-6" } do |f| %>
<% if @company.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@company.errors.count, "error") %> prohibited this person from being saved:
</h2>

<ul>
<% @company.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="form-group">
<%= f.label :name, class: 'sr-only' %>
<div class="input-group">
<div class="input-group-addon">Name</div>
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>

<div class="form-group">
<%= f.label :website, class: 'sr-only' %>
<div class="input-group">
<div class="input-group-addon">Website</div>
<%= f.url_field :website, class: 'form-control' %>
</div>
</div>

<div class="form-group">
<%= f.label :description, class: 'sr-only' %>
<div class="input-group">
<div class="input-group-addon">Description</div>
<%= f.text_area :description, class: 'form-control tall' %>
</div>
</div>

<div class="form-group">
<%= f.label :logo, class: 'sr-only' %>
<div class="input-group">
<div class="input-group-addon">Logo</div>
<%= f.file_field :logo, class: 'form-control' %>
</div>
</div>

<div class="form-group">
<%= f.submit class: 'btn btn-block btn-lg white bg-charcoal' %>
</div>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/companies/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% content_for :title, 'Edit Company' %>

<%= render 'form' %>

<%= link_to 'Back', companies_path %>
29 changes: 29 additions & 0 deletions app/views/companies/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% content_for :title, 'Companies' %>

<% content_for :utility_bar do %>
<% if !current_user.nil? && current_user.admin %>
<div class="util-head">
<div class="container">
<%= link_to new_company_path, class: 'btn' do %>
<span class="glyphicon glyphicon-plus"></span> Add Company
<% end %>
</div>
</div>
<% end %>
<% end %>

<section class="section">
<div class="container">
<% if @companies.blank? %>
<p>No companies yet.</p>
<% else %>
<div class="row inline">
<% @companies.each do |company| %>
<div class="col-sm-6 col-md-4 inline-block">
<%= render partial: "shared/company", locals: { company: company } %>
</div>
<% end %>
</div>
<% end %>
</div>
</section>
5 changes: 5 additions & 0 deletions app/views/companies/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% content_for :title, 'Add Company' %>

<%= render 'form' %>

<%= link_to 'Back', companies_path %>
53 changes: 53 additions & 0 deletions app/views/companies/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<% content_for :title, @company.name %>

<% content_for :utility_bar do %>
<% if !current_user.nil? && current_user.admin %>
<div class="util-head">
<div class="container">
<%= link_to new_company_path, class: 'btn' do %>
<span class="glyphicon glyphicon-plus"></span> Add Company
<% end %>

<% if can_edit?(@company) %>
<%= link_to edit_company_path(@company), class: 'btn' do %>
<span class="glyphicon glyphicon-edit"></span> Edit Company
<% end %>
<% end %>
</div>
</div>
<% end %>
<% end %>

<section class="section">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="resource-item">
<div class="head text-center">
<h2 class="title">
<a href="<%= @company.website %>" title="<%= @company.name %>" target="_blank">
<%= @company.name %>
</a>
</h2>
</div>
<div class="body">
<div class="description">
<%= markdown.render(@company.description).html_safe %>
<p>
<a href="<%= @company.website %>" title="<%= @company.name %>" target="_blank">
<%= @company.name %>
</a>
</p>
</div>
<div class="meta font-heading">
<h4 class="meta-title">Posted by</h4>
<span><%#= @company.user.person.full_name %></span> on <span><%= @company.created_at.strftime('%d %B %Y') %></span>
</div>
</div>
</div>

<%= render partial: 'topics/disqus' %>
</div>
</div>
</div>
</section>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div class="nav-icon ico-events"></div>
</li>
<li class="col-sm-2">
<%= link_to 'resources', resources_path %>
<%= link_to 'companies', companies_path %>
<div class="nav-icon ico-resources"></div>
</li>

Expand Down
10 changes: 10 additions & 0 deletions app/views/shared/_company.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="resource-item font-reset">
<%= link_to company_path(company), class: 'text-center head' do %>
<h2 class="title"><%= company.name %></h2>
<% end %>
<div class="body clearfix">
<div class="description">
<p><%= company.description %></p>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
end
end

resources :companies
resource :newsletters, :controller => :newsletter_signup, only: [:create, :destroy]

get '/people/claim/:slug', to: 'people#claim', as: 'people_claim'
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20171012172356_create_companies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateCompanies < ActiveRecord::Migration
def change
create_table :companies do |t|
t.string :name
t.string :logo
t.string :website
t.text :description

t.timestamps
end
end
end
Loading