Other Rails Configuration Details
Hyperstack internally sets a number of Rails configurations as outlined below.
These are all setup automatically by the hyperstack generators and installers. They are documented here for advanced configuration or in the sad chance that something gets broken during your setup. Please report any issues with setup, or if you feel you have to manually tweak things.

Require the hyperstack-loader

The app/assets/javascripts/application.js file needs to require the hyperstack-loader.
1
//= require hyperstack-loader // add as the last require directive
Copied!
The loader handles bringing in client side code, getting it compiled (using sprockets) and adding it to the webpacks (if using webpacker.)
Note that now that Rails is using webpacker by default you may have to create this file, and the single line above. If so be sure to checkout your layout file, as the javascript_include_tag will also be missing there.

app/assets/config/manifest.js

If you are using webpacker this file must exist and contain the following line:
1
//= link_directory ../javascripts .js
Copied!
This line insures that the any javascript in the assets directory are included in the webpacks. In older versions of Rails, this line will already be there, and if not using webpacker its actually not necessary (but doesn't hurt anything.)

The application layout

If using a recent version of rails with webpacker you may find that the application.html.erb file no longer loads the application.js file. Make sure that your layout file has this line:
1
<%= javascript_include_tag 'application' %>
Copied!

Required NPM modules

If using Webpacker Hyperstack needs the following NPM modules:
1
yarn 'react', '16'
2
yarn 'react-dom', '16'
3
yarn 'react-router', '^5.0.0'
4
yarn 'react-router-dom', '^5.0.0'
5
yarn 'react_ujs', '^2.5.0'
6
yarn 'jquery', '^3.4.1' # this is only needed if using jquery
7
yarn 'create-react-class'
Copied!

Routing

If using hyper-model you need to mount the Hyperstack engine in the routes file like this:
1
# config/routes.rb
2
Rails.application.routes.draw do
3
# this route should be first in the routes file so it always matches'
4
mount Hyperstack::Engine => '/hyperstack' # you can use any path you choose
5
...
Copied!
To directly route from a URL to a component you can use the builtin Hyperstack controller with a route like this:
1
get "hyperstack-page/(*others)", "hyperstack#comp_name"
Copied!
Where comp_name is the underscored name of the component you want to mount. I.e. MyComp becomes my_comp. The /(*others) indicates that all routes beginning with hyperstack-page/ will be matched, if that is your desired behavior.
Note that the engine mount point can be any string you wish but the controller routed to above is always hyperstack.

Other Rails Configuration Settings

Hyperstack will by default set a number of Rails configuration settings. To disable this set
1
config.hyperstack.auto_config = false
Copied!
In your Rails application.rb configuration file.
Otherwise the following settings are automatically applied in test and staging:
1
# This will prevent any data transmitted by HyperOperation from appearing in logs
2
config.filter_parameters << :hyperstack_secured_json
3
4
# Add the hyperstack directories
5
config.eager_load_paths += %W(#{config.root}/app/hyperstack/models)
6
config.eager_load_paths += %W(#{config.root}/app/hyperstack/models/concerns)
7
config.eager_load_paths += %W(#{config.root}/app/hyperstack/operations)
8
config.eager_load_paths += %W(#{config.root}/app/hyperstack/shared)
9
10
# But remove the outer hyperstack directory so rails doesn't try to load its
11
# contents directly
12
delete_first config.eager_load_paths, "#{config.root}/app/hyperstack"
Copied!
but in production we autoload instead of eager load.
1
# add the hyperstack directories to the auto load paths
2
config.autoload_paths += %W(#{config.root}/app/hyperstack/models)
3
config.autoload_paths += %W(#{config.root}/app/hyperstack/models/concerns)
4
config.autoload_paths += %W(#{config.root}/app/hyperstack/operations)
5
config.autoload_paths += %W(#{config.root}/app/hyperstack/shared)
6
7
# except for the outer hyperstack directory
8
delete_first config.autoload_paths, "#{config.root}/app/hyperstack"
Copied!