I encountered an error while trying to utilize the gem 'gon'. The error message reads as follows:
namer error in Quotes#index
Showing /Users/jamesbkemp/Code/QuoteEngine/app/views/layouts/application.html.erb where line #5 raised:
The error states: uninitialized constant ActionView::CompiledTemplates::Gon
Does anyone have any insights on what might be causing this issue or suggestions for alternative gems that simplify passing controller variables into JavaScript?
Thank you!
In application.html.erb, please note line 5;
<!DOCTYPE html>
<html>
<head>
<title>QuoteEngine</title>
<%= Gon::Base.render_data %>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render "layouts/navbar" %>
<% flash.each do |key, value| %>
<div class="alert alert-info alert-<%= key %>"><%= value %></div>
<% end %>
<%= yield %>
</body>
</html>
quotes_controller.rb
class QuotesController < ApplicationController
before_action :authenticate_user!, only: [ :new, :create, :edit, :update, :destroy ]
# before_action :owners_only, only: [ :show, :edit, :index, :update, :destroy ]
def new
@quote = Quote.new
end
def create
# @quote = Quote.new(quote_params)
@quote = current_user.quotes.new(quote_params)
if @quote.save
redirect_to quote_url(@quote), notice: 'Quote request created'
else
render :new
end
end>
def show
# @quote = Quote.find(params[:id])
@quote = current_user.quotes.find(params[:id])
gon.gon_quote_id = @quote.id
end
def index
@quotes = current_user.quotes.all
end>
def edit
@quote = current_user.quotes.find(params[:id])
end
def update
@quote = current_user.quotes.find(params[:id])
if @quote.update_attributes(quote_params)
redirect_to quote_path(@quote)
else
render :edit
end
end
def destroy
@quote = current_user.quotes.find(params[:id])
@quote.destroy
redirect_to quotes_path
end
private
def quote_params
params.require(:quote).permit(:gla, :prev_cover, :co_name, :co_number, :postcode, :industry, :lives_overseas,
:scheme_start_date, :payment_frequency, :commission_level)
end
end
_quote.rb partial;
<% @quote = local_assigns[:quote] %>
<section id="quotes">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<div class="panel panel-success panel-quote link-panel">
<div class="panel-heading">
<strong>GLA</strong>
</div>
<div class="panel-body text-center">
<p><strong>Quote ID; <%= @quote.id %></strong></p>
</div>
<table class="table table-bordered">
<tr>
<td>Company name</td>
<td><%= @quote.co_name %></td>
</tr>
<tr>
<td>Company number</td>
<td><%= @quote.co_number %></td>
</tr>
<tr>
<td>Office postcode</td>
<td><%= @quote.postcode %></td>
</tr>
<tr>
<td>Industry</td>
<td><%= @quote.industry %></td>
</tr>
<tr>
<td>Previous cover</td>
<td><%= @quote.prev_cover %></td>
</tr>
<tr>
<td>Lives overseas</td>
<td><%= @quote.lives_overseas %></td>
</tr>
<tr>
<td>Scheme start date</td>
<td><%= @quote.scheme_start_date %></td>
</tr>
<tr>
<td>Payment frequency</td>
<td><%= @quote.payment_frequency %></td>
</tr>
<tr>
<td>Commission level</td>
<td><%= @quote.commission_level %></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</section>
index.html.erb
<% @quotes.each do |quote| %>
<%= render :partial => "quote", locals: {quote: quote} %>
<% end %>