You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this should be added very soon to edge. In the meantime you can begin using it now!
It can be very useful to structure your models and operations into common (client and server) and server only definitions.
We have been doing this by including modules defined in app/models or app/operations with a unless RUBY_ENGINE == 'opal' guard.
This is cumbersome, and also requires moving a lot of stuff around if adding hyperstack to a brownfield site.
The require_server_side_file method solves the problem nicely. Just add that declaration to the beginning of any file in a hyperstack directory, and the matching file from the app directory will be required, BUT ONLY ON THE SERVER.
The following method can be added to the beginning of your hyperstack/models/application_record.rb file:
# app/hyperstack/models/my_big_model.rbrequire_server_side_fileclassMyBigModel < ApplicationRecord
... definitionsvisibletotheclientANDserver ...
end
# app/models/my_big_model.rbclassMyBigModel < ApplicationRecord
... definitionsonlyavailableontheserver ...
end
How it works:
the hyperstack directory is before the app directory, so rails will find the hyperstack file first. Normally once rails finds a file that defines the constant it is looking for it quits, and so the server side file wont get loaded, unless you explicitly do a require_dependency on it.
The method above simply automtically does the require_dependency, but only when running on the server.
The text was updated successfully, but these errors were encountered:
this should be added very soon to edge. In the meantime you can begin using it now!
It can be very useful to structure your models and operations into common (client and server) and server only definitions.
We have been doing this by including modules defined in app/models or app/operations with a
unless RUBY_ENGINE == 'opal'
guard.This is cumbersome, and also requires moving a lot of stuff around if adding hyperstack to a brownfield site.
The
require_server_side_file
method solves the problem nicely. Just add that declaration to the beginning of any file in a hyperstack directory, and the matching file from the app directory will be required, BUT ONLY ON THE SERVER.The following method can be added to the beginning of your hyperstack/models/application_record.rb file:
The you can say (for example)
How it works:
the hyperstack directory is before the app directory, so rails will find the hyperstack file first. Normally once rails finds a file that defines the constant it is looking for it quits, and so the server side file wont get loaded, unless you explicitly do a require_dependency on it.
The method above simply automtically does the require_dependency, but only when running on the server.
The text was updated successfully, but these errors were encountered: