Show dice rolls on table

This commit is contained in:
Trevor Vallender 2024-06-13 13:24:54 +01:00
parent 5f682dff6e
commit b024ee829b
9 changed files with 73 additions and 5 deletions

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
class EventsController < ApplicationController
layout "table"
before_action :set_table
def index
@characters = Current.user.characters.where(table: @table)
@events = @table.dice_rolls.order(:created_at)
end
private
def set_table
@table = Current.user.tables.find(params[:table_id])
end
end

View File

@ -6,4 +6,8 @@ class DiceRoll < ApplicationRecord
validates :result, presence: true,
numericality: { only_integer: true }
def display_text
"#{rollable.character.name} rolled #{rollable.name}: <strong>#{result}</strong>".html_safe
end
end

View File

@ -4,6 +4,7 @@ class Stat < ApplicationRecord
include Sluggable
belongs_to :character_sheet_section
has_one :character, through: :character_sheet_section
has_many :dice_rolls, as: :rollable, dependent: :destroy
validates :name, presence: true,

View File

@ -0,0 +1,3 @@
<li class="dice-roll">
<%= dice_roll.display_text %>
</li>

View File

@ -0,0 +1,5 @@
<% content_for :title, @table.name %>
<ul>
<%= render @events %>
</ul>

View File

@ -6,6 +6,7 @@
<% @characters.each do |character| %>
<li><%= link_to character.name, table_character_path(@table, character) %></li>
<% end %>
<li><%= link_to t(".events"), table_events_path(@table) %></li>
</ul>
</nav>
<% end %>

View File

@ -7,7 +7,7 @@
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/tables/show.html.erb",
"line": 17,
"line": 15,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => Current.user.tables.find(params[:id]).characters, {})",
"render_path": [
@ -15,7 +15,7 @@
"type": "controller",
"class": "TablesController",
"method": "show",
"line": 12,
"line": 13,
"file": "app/controllers/tables_controller.rb",
"rendered": {
"name": "tables/show",
@ -41,7 +41,7 @@
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/character_sheet_sections/index.html.erb",
"line": 7,
"line": 13,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => Current.user.characters.find(params[:character_id]).character_sheet_sections.top_level, {})",
"render_path": [
@ -49,7 +49,7 @@
"type": "controller",
"class": "CharacterSheetSectionsController",
"method": "index",
"line": 9,
"line": 10,
"file": "app/controllers/character_sheet_sections_controller.rb",
"rendered": {
"name": "character_sheet_sections/index",
@ -67,8 +67,42 @@
22
],
"note": ""
},
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "8cc5f8414893bc6d142fda5a2a91346bfe171640647dc017315ab21724170912",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/events/index.html.erb",
"line": 4,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => Current.user.tables.find(params[:table_id]).dice_rolls.order(:created_at), {})",
"render_path": [
{
"type": "controller",
"class": "EventsController",
"method": "index",
"line": 11,
"file": "app/controllers/events_controller.rb",
"rendered": {
"name": "events/index",
"file": "app/views/events/index.html.erb"
}
}
],
"updated": "2024-06-06 14:18:01 +0100",
"location": {
"type": "template",
"template": "events/index"
},
"user_input": "params[:table_id]",
"confidence": "Weak",
"cwe_id": [
22
],
"note": ""
}
],
"updated": "2024-06-13 13:24:46 +0100",
"brakeman_version": "6.1.2"
}

View File

@ -27,6 +27,7 @@ en:
sign_off_html: "<p>See you soon,<br>The Tabletop Companion team</p>"
table:
overview: Overview
events: Events
account_verifications:
show:
success: "Thanks for verifying your email address! You can now log in."

View File

@ -27,6 +27,7 @@ Rails.application.routes.draw do
resources :table_invites, only: [ :index, :edit, :update ]
resources :tables do
resources :characters, only: [ :show ]
resources :events, only: [ :index ]
resources :table_invites, only: [ :new, :create ]
end