module Orchestrate::Rails::Tutorial::GetEvents
Getting orchestrate.io events¶ ↑
The films example application includes a comment
feature that provides the ability to associate comments with each film in
the collection. This feature is implemented using orchestrate.io's
time-ordered events.
Updating the Film model to get orchestrate.io events.¶ ↑
Update <rails-root>/app/models/film.rb
to add the
commments
method.
class Film < Orchestrate::Rails::Model def comments self.events('comments') end end
Updating the films controller.¶ ↑
Update <rails-root>/app/controllers/films_controller.rb
to call the comments method from the show
action:
class FilmsController < ApplicationController def index @films = Film.all end def show @film = Film.find params[:id] @comments = @film.comments end end
Updating the view to display comment events.¶ ↑
Update <rails-root>/app/views/films/show.html.haml
as
shown:
%ul.films.list-group %li.list-group-item %h3.list-group-item-heading= @film.title %ul.list-group %li.list-group-item = render partial: 'films/film_info' - if @comments and @comments.length > 0 %li.list-group-item = render partial: 'films/comments', locals: { comments: @comments }
Now we'll add the partial view that displays the comments.
Create <rails-root>/app/views/films/_comments.html.haml
as shown:
%h3.list-group-item-heading= "Comments" %ul.list-group %li.list-group-item .row.list-group-item-heading .col-md-3.col-md-offset-1= "USER" .col-md-7= "COMMENT" - comments.each do |comment| .row.film-comment .col-md-3.col-md-offset-1.film-heading= comment.user.humanize.titleize .col-md-7= comment.text
Let's check it out¶ ↑
Navigate to “The Godfather” to see its comments.