Example:
We have movie with rating, which gets from IMDB
This file contains 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 | |
def show | |
@movie = Movie.find(params[:id]) | |
@movie_rating = IMDB.movie_rating(@movie) | |
end | |
end | |
# app/views/movies/show.html.haml | |
%h1 | |
Information about #{@movie.title} | |
%p= @movie.description | |
%p | |
Movie rating on IMDB: #{@movie_rating} |
But page will load only after rating got from IMDB site.
To not wait for it - we use async
This file contains 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 | |
%h1 | |
Information about #{@movie.title} | |
%p= @movie.description | |
= render_async movie_rating_path(@movie.id) | |
# config/routes.rb | |
get :movie_rating, controller: :movies | |
# app/controllers/movies_controller.rb | |
def movie_rating | |
@movie_rating = IMDB.movie_ratings(@movie) | |
render partial: 'movie_ratings' | |
end | |
# app/views/movies/_movie_rating.html.erb | |
%p | |
Movie rating on IMDB: #{@movie_rating} | |
# app/views/layouts/application.html.erb | |
= content_for :render_async |
https://semaphoreci.com/
Comments
Post a Comment