Skip to content

Commit

Permalink
Adding controller and Views for Organizations and a Homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Saakshaat committed May 24, 2020
1 parent 77901f9 commit b938a2d
Show file tree
Hide file tree
Showing 30 changed files with 7,976 additions and 3 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
3 changes: 3 additions & 0 deletions app/assets/stylesheets/homepage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Homepage controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/organizations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Organizations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
4 changes: 4 additions & 0 deletions app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class HomepageController < ApplicationController
def index
end
end
49 changes: 49 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class OrganizationsController < ApplicationController
def index
@organization = Organization.all
end

def new
@organization = Organization.new
end

def edit
@organization = Organization.find(params[:id])
end

def create
@organization = Organization.new(organization_params)

if @organization.save
redirect_to @organization
else
render 'new'
end
end

def show
@organization = Organization.find(params[:id])
end

def update
@organization = Organization.find(params[:id])

if @organization.update(organization_params)
redirect_to @organization
else
render 'edit'
end
end

def destroy
@organization = Organization.find(params[:id])
@organization.destroy

redirect_to organizations_path
end

private
def organization_params
params.require(:organization).permit(:name, :description, :size)
end
end
2 changes: 2 additions & 0 deletions app/helpers/homepage_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HomepageHelper
end
2 changes: 2 additions & 0 deletions app/helpers/organizations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OrganizationsHelper
end
5 changes: 4 additions & 1 deletion app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

//= require jquery
//= require jquery_ujs


require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")


// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
Expand Down
1 change: 1 addition & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Organization < ApplicationRecord
validates :name, presence: true, length: { minimum: 5 }
validates :description, presence: true, length: { minimum: 20 }
validates :size, numericality: { only_integer: true, greater_than_or_equal_to: 1}
end
2 changes: 2 additions & 0 deletions app/views/homepage/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Project Matching</h1>
<%= link_to 'Organizations', controller: 'organizations' %>
34 changes: 34 additions & 0 deletions app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%= form_with(model: @organization, local: true) do |form| %>
<div>
<% if @organization.errors.any? %>
<div id="error_explanation">
<h2>
Fix <%= pluralize(@organization.errors.count, "error") %> errors:
</h2>
<ul>
<% @organization.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
<p>
<%= form.label :name %><br>
<%= form.text_field :name %>
</p>

<p>
<%= form.label :description %><br>
<%= form.text_area :description %>
</p>

<p>
<%= form.label :size %><br>
<%= form.number_field :size %>
</p>

<p>
<%= form.submit %>
</p>
<%end %>
3 changes: 3 additions & 0 deletions app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Edit Organization Details</h1>
<%= render 'form' %>
<%= link_to 'Back', organizations_path %>
16 changes: 16 additions & 0 deletions app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1>Find your Organization</h1>
<h5>
<%= link_to 'Create Organization', new_organization_path %>
</h5>

<h4>Current Organizations</h4>

<br><br><br>

<% @organization.each do |organization| %>
<%= organization.name %>
<%= link_to 'Show', organization_path(organization) %>
<%end%>
<footer>
<%= link_to 'Home', 'homepage/index' %>
</footer>
3 changes: 3 additions & 0 deletions app/views/organizations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>New Organization</h2>
<%= render 'form' %>
<%= link_to 'Go Back', organizations_path %>
21 changes: 21 additions & 0 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<p>
<strong>Name:</strong>
<%= @organization.name %>
</p>

<p>
<strong>Description:</strong>
<%= @organization.description %>
</p>

<p>
<strong>Size:</strong>
<%= @organization.size %>
</p>

<%= link_to 'Edit', edit_organization_path(@organization) %>
<%= link_to 'Back', organizations_path %>
<br><br><br><br><br>
<footer>
<%= button_to 'Delete Organization', organization_path(@organization), :method => :delete, data: { confirm: 'You sure, homie?' } %>
</footer>
72 changes: 72 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')

if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}

return {
presets: [
isTestEnv && [
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
18 changes: 18 additions & 0 deletions bin/webpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "bundler/setup"

require "webpacker"
require "webpacker/webpack_runner"

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
end
18 changes: 18 additions & 0 deletions bin/webpack-dev-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "bundler/setup"

require "webpacker"
require "webpacker/dev_server_runner"

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::DevServerRunner.run(ARGV)
end
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get 'homepage/index'
resources :organizations

root 'homepage#index'
end
5 changes: 5 additions & 0 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
3 changes: 3 additions & 0 deletions config/webpack/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { environment } = require('@rails/webpacker')

module.exports = environment
5 changes: 5 additions & 0 deletions config/webpack/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
5 changes: 5 additions & 0 deletions config/webpack/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
Loading

0 comments on commit b938a2d

Please sign in to comment.