Skip to content

Instantly share code, notes, and snippets.

@gabytabs
Created June 9, 2017 05:11
Show Gist options
  • Select an option

  • Save gabytabs/989e34f16e40dc1f88ebea76f5316eda to your computer and use it in GitHub Desktop.

Select an option

Save gabytabs/989e34f16e40dc1f88ebea76f5316eda to your computer and use it in GitHub Desktop.

Revisions

  1. gabytabs created this gist Jun 9, 2017.
    13 changes: 13 additions & 0 deletions index.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <%= 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 %>
    21 changes: 21 additions & 0 deletions index_post.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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
    }
    }
    })
    }
    })
    9 changes: 9 additions & 0 deletions post_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    class PostsController < ApplicationController

    # GET /posts
    # GET /posts.json
    def index
    @posts = Post.all
    end

    end