[RUBY] [Vue Rails] "Hello Vue!" Displayed with Vue + Rails

Vue + Rails app creation

◆ Rails app creation

// "-webpack=vue"Optional Vue.js available
$ rails new <Application name> -webpack=vue

◆ model creation

//Column name: name Data type: text
$ rails g model sample name:text

◆ Migration file editing (not required for Hello.Vue! Display)


class CreateSample < ActiveRecord::Migration[6.0]
  def change
    create_table :sample do |t|
      t.text :name, null: false, default: ""

◆ Migration

$ rails db:create      //Database creation
$ rails db:migrate    //Migration implementation

◆ Controller creation


class HomeController < ApplicationController
  def index

◆ Edit routes.rb


Rails.application.routes.draw do
  root to: 'home#index'

◆ Edit index.html.erb


<%= javascript_pack_tag 'hello_vue' %>
<%= stylesheet_pack_tag 'hello_vue' %>

◆ hello.vue.js (set by default)


import Vue from 'vue'
import App from '../app.vue'

document.addEventListener('DOMContentLoaded', () => {
  const el = document.body.appendChild(document.createElement('hello'))
  const app = new Vue({
    render: h => h(App)


◆ app.vue (set by default)


  <div id="app">
    <p>{{ message }}</p>

export default {
  data: function () {
    return {
      message: "Hello Vue!"

<style scoped>
p {
  font-size: 2em;
  text-align: center;


◆ before_action --Define a method and set it to before_action


class LoginController < ApplicationController
  before_action :set_answer
  def set_answer
    @sample = "Hello World!"  

◆ rescue_from --Exception handling. Set the screen for error handling --Write in `ʻapp / controller / application_controller.rb``


class ApplicationController < ActionController::Base

  rescue_from ActiveRecord::RecordNotFound, with: :rescue404


Error encountered

◆ Error details ①

Webpacker::Manifest::MissingEntryError in Home#index

Solution: Webpack installation

$ yarn
$ bin/yarn
$ webpack
$ webpack

◆ Error details ②

Error: vue-loader requires @vue/compiler-sfc to be present in the dependency tree.

Solution: vue-loader downgrade

$ npm remove vue-loader
$ npm install --save [email protected]
$ yarn add [email protected]

◆ Error details ③

Sprockets::Rails::Helper::AssetNotFound in Home#index
 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

Solution: Edit app / views / layouts / application.html.erb


<!-- javascript_include_Delete tag line-->
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>


-Introduction to modern web applications starting with Ruby on Rails, Vue.js -I made something like a TODO app tutorial with Vue.js and Rails -Useful in practice! How to use before_action of Ruby on Rails [For beginners] -[[Rails] Error collection that tends to trip during installation](Webpacker :: Manifest :: MissingEntryError in Home # index) -Error: vue-loader requires @ vue / compiler-sfc to be present in the dependency tree # 1672 -[Npm / yarn] Downgrade the package

Recommended Posts

[Vue Rails] "Hello Vue!" Displayed with Vue + Rails
I tried writing CRUD with Rails + Vue + devise_token_auth
Easy to display hello world with Rails + Docker
Rails deploy with Docker
[Rails 6] RuntimeError with $ rails s
Handle devise with Rails
[Rails] Learning with Rails tutorial
[Rails] Test with RSpec
[Rails] Development with MySQL
Supports multilingualization with Rails!
Hello World with Micronaut
Double polymorphic with Rails
Hello World with Spring Boot
Introduced graph function with rails
[Rails] Express polymorphic with graphql-ruby
[Rails] Upload videos with Rails (ActiveStorage)
Try using view_component with rails
Japaneseize using i18n with Rails
Hello World with Spring Boot!
API creation with Rails + GraphQL
Preparation for developing with Rails
Hello World with VS Code!
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
[Rails] Specify format with link_to
Login function implementation with rails
Hello World with Spring Boot
Hello World with SpringBoot / Gradle
[Rails] fields_for is not displayed
[Docker] Use whenever with Docker + Rails
Building an environment for creating apps with Rails and Vue
Hello, World! With Asakusa Framework!
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Create portfolio with rails + postgres sql
[Rails] Push transmission with LINE Bot
Implemented mail sending function with rails
[Rails] Creating a new project with rails new
Minimal Rails with reduced file generation
Create pagination function with Rails Kaminari
Build environment with vue.js + rails + docker
Eliminate Rails FatModel with value object
Until "Hello World" with Spring Boot
Hello world with Kotlin and JavaFX
Recognize Rails projects with Intellij idea
Hello World with Docker and C
[Grover] Generate PDF with Rails [2020 version]
Build Rails environment with Docker Compose
[Rails] Initial data creation with seed
(Intellij) Hello World with Spring Boot
Track Rails app errors with Sentry
Hello World with GlassFish 5.1 + Servlet + JSP
Create PDF with itext7 ~ Hello World ~
[Environment construction with Docker] Rails 6 & MySQL 8
Connect to Rails server with iPhone
How to get along with Rails
"Hello world" for ImageJ with Eclipse
Create My Page with Rails devise
Introducing React to Rails with react-rails