@@ -2,3 +2,75 @@ vue-form-for
22============
33
44A custom Rails form builder for Vue.js
5+
6+ Synopsis
7+ -----
8+
9+ ```
10+ <%= vue_form_for User.new do |f| %>
11+ <%= f.text_field :name %>
12+ <%= f.submit "Create" %>
13+ <% end %>
14+ ```
15+
16+ The above ERB template will be rendered into the following HTML fragment:
17+
18+ ``` html
19+ <form class =" new_user" id =" new_user" action =" /users" accept-charset =" UTF-8" method =" post" >
20+ <input name =" utf8" type =" hidden" value =" ✓ ; " />
21+ <input type =" hidden" name =" authenticity_token" value =" ..." />
22+ <input v-model =" user.name" type =" text" name =" user[name]" id =" user_name" />
23+ <input type =" submit" name =" commit" value =" Create" />
24+ </form >
25+ ```
26+
27+ Note that the third ` <input> ` element has a ` v-model ` attriubte, which can be
28+ interpreted by Vue.js as the _ directive_ to create two-way data bindings between
29+ form fields and component's data.
30+
31+ If you are using the [ Webpacker] ( https://github.com/rails/webpacker ) ,
32+ create ` app/javascript/packs/new_user_form.js ` with following code:
33+
34+ ``` javascript
35+ import Vue from ' vue/dist/vue.esm'
36+
37+ document .addEventListener (" DOMContentLoaded" , () => {
38+ const NewUserForm = new Vue ({
39+ el: " #new_user" ,
40+ data: {
41+ user: {
42+ name: " "
43+ }
44+ }
45+ })
46+ })
47+ ```
48+
49+ Add this line to the ERB template:
50+
51+ ``` text
52+ <%= javascript_pack_tag 'new_user_form' %>
53+ ```
54+
55+ Then, you can get the value of ` user[name] ` field by the ` user.name ` .
56+
57+ Installation
58+ ------------
59+
60+ Add the following line to ` Gemfile ` :
61+
62+ ``` ruby
63+ gem ' vue-form-for'
64+ ```
65+
66+ Run ` bundle install ` on the terminal.
67+
68+ License
69+ -------
70+
71+ The ` initial-test-data ` is distributed under the MIT license. ([ MIT-LICENSE] ( https://github.com/oiax/initial-test-data/blob/master/MIT-LICENSE ) )
72+
73+ Author
74+ ------
75+
76+ Tsutomu Kuroda (
[email protected] )
0 commit comments