Skip to content

Instantly share code, notes, and snippets.

View nikolalsvk's full-sized avatar
🍍

Nikola Đuza nikolalsvk

🍍
View GitHub Profile
<script>
export let name;
</script>
<style>
h1 {
color: #FF3E00;
}
</style>
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
<!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' %>
/* 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', () => {
$ rails new rails-6-svelte # Generate Rails app and install all dependencies
$ cd rails-6-svelte # Step into our new app
<!-- app/views/movies/show.html.erb -->
<%= render_async movie_rating_path(@movie),
interval: 2000,
error_message: "Couldn't load rating :(" %>
<!-- app/views/movies/show.html.erb -->
<%= render_async movie_rating_path(@movie), interval: 2000 %>
<!-- 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;
<!-- app/views/movies/_movie_rating.html.erb -->
Movie rating: <%= @rating %>
# app/controllers/movies_controller.rb
class MoviesController < ApplicationController
# somewhere inside Movies controller
def rating
@rating = @movie.rating
render partial: 'movie_rating'
end
end