Created
June 9, 2017 05:11
-
-
Save gabytabs/989e34f16e40dc1f88ebea76f5316eda to your computer and use it in GitHub Desktop.
Vue on rails
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
| <%= content_tag :div, | |
| id: "post-index", | |
| data: { | |
| posts: @posts.to_json(except: [:id, :created_at, :updated_at]) | |
| } do %> | |
| <h1> Posts </h1> | |
| <div v-for="post in posts"> | |
| <h2>{{post.tweet}}</h2> | |
| </div> | |
| <% end %> |
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
| import Vue from 'vue/dist/vue.js' | |
| import TurbolinksAdapter from 'vue-turbolinks' | |
| document.addEventListener('turbolinks:load', () => { | |
| var element = document.getElementById("post-index") | |
| if (element != null) { | |
| var posts = JSON.parse(element.dataset.posts) | |
| var post_index = new Vue({ | |
| el: element, | |
| mixins: [TurbolinksAdapter], | |
| data: function(){ | |
| return { | |
| posts: posts | |
| } | |
| } | |
| }) | |
| } | |
| }) |
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
| class PostsController < ApplicationController | |
| # GET /posts | |
| # GET /posts.json | |
| def index | |
| @posts = Post.all | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment