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
{{ message }}
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
In a few places we have used attr_accessor to allow us to set flags and whatnot remotely. In old versions this just worked, aka you assign on the client and it gets sent via execute_remote and is assigned on the server. In lap27 it changed slightly, you'd have to do server_method(:ivar) {} which for some reason enabled ivar = "bar" to work. In lap28 it doesn't work at all. I'm assuming Hyperloop uses the columns has to decide what is assignable.
user.field="foo"# setting a field worksuser.ivar="bar"# setting an instance variable doesn't get sent to server
This was probably never intended behaviour but it is useful. E.g.:
For uploading avatars we base64 encode them and assigned to a data_avatar= then on the server process, save, and assign the real file to avatar.
To enable partial validations during a very long signup flow we had a force_validate= that took an array of fields, then we checked that on the server with conditional validations.
My temporary workaround is to screw with public_columns_hash to add the virtual attributes we need. This seems brittle so it would be nice to have a supported way of sending ivars over Hypermesh.
moduleActiveRecordclassBasedefself.public_columns_hashreturn@public_columns_hashif@public_columns_hash && Rails.env.production?files=[]Hyperloop.public_model_directories.eachdo |dir|
dir_length=Rails.root.join(dir).to_s.length + 1Dir.glob(Rails.root.join(dir,'**','*.rb')).eachdo |file|
require_dependency(file)# still the file is loaded to make sure for development and test envfiles << file[dir_length..-4]endend@public_columns_hash={}# descendants only works for already loaded models!descendants.eachdo |model|
iffiles.include?(model.name.underscore) && model.name.underscore != 'application_record'@public_columns_hash[model.name]=model.columns_hash.clonerescuenil# why rescue? | extremely important .clonebegin@public_columns_hash[model.name]["force_validate"]=User.columns_hash["first_name"].clone# just stealing a string field as a template@public_columns_hash[model.name]["force_validate"].instance_variable_set(:@name,"force_validate")# correct the name@public_columns_hash[model.name]["force_validate"].instance_variable_set(:@table_name,model.table_name)# correct the tablerescueendendend@public_columns_hashendendend
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In a few places we have used
attr_accessor
to allow us to set flags and whatnot remotely. In old versions this just worked, aka you assign on the client and it gets sent via execute_remote and is assigned on the server. In lap27 it changed slightly, you'd have to doserver_method(:ivar) {}
which for some reason enabledivar = "bar"
to work. In lap28 it doesn't work at all. I'm assuming Hyperloop uses the columns has to decide what is assignable.This was probably never intended behaviour but it is useful. E.g.:
data_avatar=
then on the server process, save, and assign the real file toavatar
.force_validate=
that took an array of fields, then we checked that on the server with conditional validations.My temporary workaround is to screw with public_columns_hash to add the virtual attributes we need. This seems brittle so it would be nice to have a supported way of sending ivars over Hypermesh.
The text was updated successfully, but these errors were encountered: