Commit 4e96db0

mo <mo.khan@gmail.com>
2018-04-07 19:47:54
replace inline js with stimulus controller.
1 parent ee9b444
app/javascript/controllers/sessions/response_controller.js
@@ -0,0 +1,9 @@
+import { Controller } from "stimulus"
+
+export default class extends Controller {
+  connect() {
+    setTimeout(() => {
+      this.element.submit();
+    }, 5000);
+  }
+}
app/javascript/packs/application.js
@@ -13,6 +13,7 @@ import 'bootstrap/dist/js/bootstrap';
 import { Application } from "stimulus"
 import { definitionsFromContext } from "stimulus/webpack-helpers"
 
-const application = Application.start()
-const context = require.context("controllers", true, /.js$/)
-application.load(definitionsFromContext(context))
+const application = Application.start();
+const context = require.context("controllers", true, /.js$/);
+console.log('found controllers', definitionsFromContext(context));
+application.load(definitionsFromContext(context));
app/views/sessions/_response.html.erb
@@ -3,7 +3,7 @@
     <div class="col">
       <h1>Sending Response to Service Provider</h1>
       <%= render partial: 'spinner' %>
-      <%= form_tag(@url, style: "position: absolute; left: -10000px; top: -10000px;") do %>
+      <%= form_tag(@url, data: { controller: 'sessions--response' }) do %>
         <% @saml_params.each do |(key, value)| %>
           <%= hidden_field_tag key, value %>
         <% end %>
@@ -12,9 +12,3 @@
     </div>
   </div>
 </div>
-
-<%= javascript_tag do %>
-  window.onload = function () {
-    window.setTimeout(function() { document.forms[0].submit(); }, 5000);
-  };
-<% end %>
bin/server
@@ -1,6 +1,19 @@
 #!/bin/sh
 
+# script/server: Launch the application and any extra required processes locally.
+
+set -e
+cd "$(dirname "$0")/.."
+
 if [ ! "$RAILS_ENV" = "production" ] ; then
+  PROCFILE=Procfile.development
   bin/webpack
+else
+  PROCFILE=Procfile
+fi
+test -z "$RACK_ENV" && RACK_ENV='development'
+if [ -n "$1" ]; then
+  bundle exec foreman start "$1" -f $PROCFILE
+else
+  bundle exec foreman start -f $PROCFILE
 fi
-bin/rails server
config/application.rb
@@ -8,6 +8,7 @@ require 'rails/all'
 # you've limited to :test, :development, or :production.
 Bundler.require(*Rails.groups)
 
+Dotenv.load(".env.local", ".env.#{Rails.env}", ".env")
 module Proof
   class Application < Rails::Application
     # Initialize configuration defaults for originally generated Rails version.
Gemfile
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 source 'https://rubygems.org'
+ruby '2.5.1'
 
 git_source(:github) do |repo_name|
   repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
@@ -10,8 +11,9 @@ end
 gem 'activerecord-session_store'
 gem 'bcrypt', '~> 3.1.7'
 gem 'coffee-rails', '~> 4.2'
-gem 'dotenv-rails'
+gem 'dotenv'
 gem 'email_validator'
+gem 'foreman'
 gem 'jbuilder', '~> 2.5'
 gem 'jwt'
 gem 'puma', '~> 3.7'
Gemfile.lock
@@ -78,9 +78,6 @@ GEM
     crass (1.0.3)
     diff-lcs (1.3)
     dotenv (2.2.1)
-    dotenv-rails (2.2.1)
-      dotenv (= 2.2.1)
-      railties (>= 3.2, < 5.2)
     email_validator (1.6.0)
       activemodel
     erubi (1.7.1)
@@ -92,6 +89,9 @@ GEM
       railties (>= 3.0.0)
     ffaker (2.9.0)
     ffi (1.9.23)
+    foreman (0.63.0)
+      dotenv (>= 0.7)
+      thor (>= 0.13.6)
     globalid (0.4.1)
       activesupport (>= 4.2.0)
     hashdiff (0.3.7)
@@ -281,10 +281,11 @@ DEPENDENCIES
   byebug
   capybara (~> 2.13)
   coffee-rails (~> 4.2)
-  dotenv-rails
+  dotenv
   email_validator
   factory_bot_rails
   ffaker
+  foreman
   jbuilder (~> 2.5)
   jwt
   listen (>= 3.0.5, < 3.2)
@@ -310,5 +311,8 @@ DEPENDENCIES
   webmock
   webpacker
 
+RUBY VERSION
+   ruby 2.5.1p57
+
 BUNDLED WITH
    1.16.1
Procfile.development
@@ -0,0 +1,2 @@
+web: bin/rails s -p $PORT
+webpack: ./bin/webpack-dev-server