给定Rails控制器中的这些强参数:
def user_params params.require(:user).permit(details: [{ group: %i[type value] }]) end
字符串如何在将details数组持久化到JSONB列之前对其进行清理?
details
xxe27gdn1#
我为其他有类似问题的人写了一个解决方案:
include ActionView::Helpers::SanitizeHelper # ... private def sanitize_details return unless details self.details = details.map do |group| sanitized_details = group['group'].map do |detail| { type: sanitize_most(detail['type']), value: sanitize_most(detail['value']) } end { group: sanitized_details } end end def sanitize_most(field) sanitize(field, tags: %w[a b i strong em], attributes: %w[href rel target]) end
字符串
1条答案
按热度按时间xxe27gdn1#
我为其他有类似问题的人写了一个解决方案:
字符串