Skip to content

Commit c73f2ff

Browse files
committed
Add initial implementation
1 parent 7f5c3df commit c73f2ff

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

lib/vue-form-for.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'vue-form-for/form_builder'
2+
require 'vue-form-for/railtie' if defined?(Rails)

lib/vue-form-for/form_builder.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module VueFormFor
2+
class FormBuilder < ActionView::Helpers::FormBuilder
3+
(field_helpers - [:label, :fields_for]).each do |selector|
4+
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
5+
def #{selector}(method, options = {})
6+
options[:"v-model"] ||= "\#{@object_name}.\#{method}"
7+
super(method, options)
8+
end
9+
RUBY_EVAL
10+
end
11+
end
12+
end

lib/vue-form-for/form_helpers.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module VueFormFor
2+
module FormHelpers
3+
def vue_form_for(record, options = {}, &block)
4+
options[:builder] ||= VueFormFor::FormBuilder
5+
form_for(record, options, &block)
6+
end
7+
end
8+
end

lib/vue-form-for/railtie.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'vue-form-for/form_helpers'
2+
3+
module VueFormFor
4+
class Railtie < Rails::Railtie
5+
initializer "vue-form-for.view_form_helpers" do
6+
ActiveSupport.on_load :action_view do
7+
include VueFormFor::FormHelpers
8+
end
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)