Created
May 2, 2017 15:47
-
-
Save et/e2a5442a6c6e7ac00ad8126f211330c3 to your computer and use it in GitHub Desktop.
Adding errors to all active admin forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dir.glob('app/admin/*.rb') do |file_name| | |
File.open(file_name, "r") do |f| | |
text = File.read(f) | |
form_matches = text.match(/form do \|(?<block_param>\w+)\|/) | |
if form_matches && form_matches[:block_param] | |
semantic_errors_matches = text.match(/#{form_matches[:block_param]}.semantic_errors\(\*f\.object\.errors\.keys\)/) | |
if !semantic_errors_matches | |
text.gsub!(form_matches.to_s, form_matches.to_s + "\n" + " " + "#{form_matches[:block_param]}.semantic_errors(*#{form_matches[:block_param]}.object.errors.keys)") | |
File.open(file_name, "w") {|file| file.puts text } | |
end | |
else | |
# puts "#{file} has no form" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment