Good ... I decided to share with the community the experience of integrating Vue.js v2 and Ruby on Rails on the example of developing a chat. To do this, we need an implementation of the websocket in Rails - ActionCable.
This is the first part of several articles so as not to pile everything up and apply a phased approach to development. This part basically repeats the already existing article, the link to which is given below, but it is necessary to trace the entire development process in stages. Interested - under cat.
gem install webpacker rails new chat --webpack=vue gem 'foreman' bundle update #Procfile backend: bin/rails s -p 3000 frontend: bin/webpack-dev-server rails g resource Message body:text username:string # app/controllers/messages_controller.rb class MessagesController < ApplicationController def index end def create end end #config/routes.rb: Rails.application.routes.draw do resources :messages root to: 'messages#index' end <template> <div id="app"> <p>{{ message }}</p> </div> </template> <script> export default { data: function () { return { message: "Hello Vue!" } } } </script> <style scoped> p { font-size: 2em; text-align: center; } </style> import Vue from 'vue' import App from './components/app.vue' document.addEventListener('DOMContentLoaded', () => { const el = document.body.appendChild(document.createElement('application')) const app = new Vue({ el, render: h => h(App) }) console.log(app) }) <head> <title>Chat</title> <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all' %> <%= stylesheet_pack_tag 'application', media: 'all' %> <%= javascript_pack_tag 'application' %> <!-- <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> --> </head> bundle binstubs bundler --force foreman start Source: https://habr.com/ru/post/349912/
All Articles