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
<script> | |
export let name; | |
</script> | |
<style> | |
h1 { | |
color: #FF3E00; | |
} | |
</style> |
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
Rails.application.routes.draw do | |
get 'welcome/index' | |
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html | |
root 'welcome#index' | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Rails6Svelte</title> | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> | |
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> | |
<%= javascript_pack_tag 'hello_svelte' %> |
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
/* eslint no-console: 0 */ | |
// Run this example by adding <%= javascript_pack_tag 'hello_svelte' %> (and | |
// <%= stylesheet_pack_tag 'hello_svelte' %> if you have styles in your component) | |
// to the head of your layout file, | |
// like app/views/layouts/application.html.erb. | |
// All it does is render <div>Hello Svelte!</div> at the bottom of the page. | |
import App from '../app.svelte' | |
document.addEventListener('DOMContentLoaded', () => { |
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
$ rails new rails-6-svelte # Generate Rails app and install all dependencies | |
$ cd rails-6-svelte # Step into our new app |
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
<!-- app/views/movies/show.html.erb --> | |
<%= render_async movie_rating_path(@movie), | |
interval: 2000, | |
error_message: "Couldn't load rating :(" %> |
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
<!-- app/views/movies/show.html.erb --> | |
<%= render_async movie_rating_path(@movie), interval: 2000 %> |
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
<!-- app/views/movies/show.html.erb --> | |
<div id="rating">Loading rating...</div> | |
<script> | |
const checkRating = () => { | |
fetch("<%= movie_rating_path(@movie) %>") | |
.then(response => response.text()) | |
.then(response => { | |
document.getElementById("rating").innerHTML = response; |
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
<!-- app/views/movies/_movie_rating.html.erb --> | |
Movie rating: <%= @rating %> |
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
# app/controllers/movies_controller.rb | |
class MoviesController < ApplicationController | |
# somewhere inside Movies controller | |
def rating | |
@rating = @movie.rating | |
render partial: 'movie_rating' | |
end | |
end |