-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.rb
37 lines (32 loc) · 1.25 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'open-uri'
def read_file(url)
URI.open(url).read
rescue OpenURI::HTTPError => e
puts "Failed to download file: #{e.message}"
nil
rescue StandardError => e
puts "Error reading file: #{e.message}"
nil
end
form_builder_content = read_file("https://raw.githubusercontent.com/brandnewbox/app-form-builder/main/app_form_builder.rb")
create_file "app/helpers/app_form_builder.rb", form_builder_content
create_file "app/helpers/app_form_builder_helper.rb", <<~RUBY
module AppFormBuilderHelper
def app_form_with(*, **, &)
AppFormBuilder.with_blank_error_proc do
form_with(*, builder: AppFormBuilder, **, &)
end
end
end
RUBY
if File.exist?("app/controllers/application_controller.rb")
insert_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
" default_form_builder AppFormBuilder\n"
end
end
create_file "config/initializers/blank_form_error_proc.rb", <<~RUBY
# Prevent Rails from adding a default error class to form fields
# This is necessary to allow our custom form builder to style the error messages
# https://github.com/brandnewbox/app-form-builder
Rails.application.config.action_view.field_error_proc = Proc.new { |tag, instance| tag }
RUBY