ruby - Rails: default serializers and safe_params to all fields in the model -
this question has answer here:
in rails / angular app passing data front-end via rails serializers, , permitting updates fields via params.permit.
i understand part of purpose of serializer/safe_params control comes , goes server. however, models, finding need include fields.
is there metaprogramming or other method body of serailizer , safe_params can simple expose / accept fields on model, including virtual fields?
example code
serializer
class batchserializer < activemodel::serializer attributes :id, :description, :details, :user_id, :name, :dataset, :dataset_id, :pairs_per_sequence, :pairs_per_bp, :batch_type, :overlap_size, :padding, :assembly_id, :multiplex_tolerance, :run_id, :snp_mask, :primer3_parameter_id, :specificity_check, :batch_status, :avoid_cross_primers, :temperature_similarity, :gibbs_free_energy, :base_termination, :wet_lab end
controller safe_params
def safe_params params.permit(:id, :description, :details, :user_id, :name, :dataset, :dataset_id, :pairs_per_sequence, :pairs_per_bp, :batch_type, :overlap_size, :padding, :assembly_id, :multiplex_tolerance, :run_id, :snp_mask, :primer3_parameter_id, :specificity_check, :avoid_cross_primers, :temperature_similarity, :gibbs_free_energy, :base_termination, :wet_lab_result) end
edit
this post offers answer half of problem: permit rails 4 strong parameters : permit attributes?
so how automatically serialize fields?
if stop passing in serializer, rails use default serializer renders attributes default.
eg, suppose have model called myobject
, can render with:
render :json => my_object
re: permitting attributes - can take @ rails 4 strong parameters : permit attributes? that.
Comments
Post a Comment