You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/essential/07_partials_and_custom_components.md
-32Lines changed: 0 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -223,38 +223,6 @@ Using ur custom component is as easy as calling the name we defined in our regis
223
223
224
224
When you start your application locally now, the missing list bullet points should be the only visible change. We will take care of styling soon - but first, let's reuse our newly introduced component!
225
225
226
-
----
227
-
# Refactor from here
228
-
----
229
-
230
-
## Reusing the custom component
231
-
How about displaying three random persons from the database on the person show page, each within a card? It's as simple as below:
We query the database for three random records in the `prepare` method, add a partial for better composability and then loop through the records, handing each record as input to our custom card component!
257
-
258
226
## Using HAML in custom components
259
227
260
228
If you need more fine-grained control of your view layer or want to reuse some old HAML files, you can also create custom components like this:
Our vue.js component renders a div containing a paragraph and a list. The paragraph contains some text and a button. We set a `v-on:click` event handler like you would normally do in vue.js with its shorter version `@click`. This means the button will call the `addActivity` method from its corresponding vue.js component. In the list below we assume that our javascript vue.js component has an `activities` array. We loop over it, again using vue.js directives and display each activity with a button labelled 'Remove' which calls `deleteActivity(index)` if clicked.
46
47
47
-
Like stated above, a `Matestack::Ui::VueJsComponent` requires a javascript counterpart. Let's create it aside our ruby component in `app/matestack/components/persons/activity.js`
48
+
Like stated above, a `Matestack::Ui::VueJsComponent` requires a javascript counterpart.
49
+
Inside we define a vue.js component and give it a name. The name needs to equal the name we defined in our ruby component at the top with `vue_js_component_name`. This settings is necessary in order to connect the javascript component with our ruby component.
50
+
Let's create it aside our ruby component in `app/matestack/components/persons/activity.js`
0 commit comments