Airbrake error: #3484
Airbrake project: First project
Error type: ActionView::SyntaxErrorInTemplate
Error message: Encountered a syntax error while rendering template: check -#force links to open in parent not iframe %base{target: '_blank'} %table.weather_table %tr %th Wind Station %th MPH %th Direction %th Temp %th Age %th Location %th MSL feet - @observations.each do |observation| - next if observation.station_id == 'KCOBOULD199' - station_data = DisplayWeatherStation.station_data(observation.station_id) %tr %td.station{class: "#{wind_class(observation...
Where: weather_station#index
Occurred at: Aug 28, 2020 12:11:12 UTC
First seen at: Aug 28, 2020 12:11:12 UTC
Occurrences: 0 (0 since last deploy on <no information>
)
Severity: error
URL: http://localhost:3000/weather_station/index
File: /GEM_ROOT/gems/actionview-6.0.3.2/lib/action_view/template.rb
Backtrace:
/GEM_ROOT/gems/actionview-6.0.3.2/lib/action_view/template.rb:340:in module_eval
/GEM_ROOT/gems/actionview-6.0.3.2/lib/action_view/template.rb:340:in compile
/GEM_ROOT/gems/actionview-6.0.3.2/lib/action_view/template.rb:284:in block (2 levels) in compile!
/GEM_ROOT/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:182:in instrument
...
Caused by SyntaxError: /Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:33: syntax error, unexpected '}', expecting =>
... : {observation.air_temp.round}
... ^
/Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:37: syntax error, unexpected `else', expecting ')'
...<< ("n</td>n".freeze);; else
... ^~~~
/Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:41: syntax error, unexpected `end', expecting ')'
...-n</td>n".freeze);; end;; end;; _hamlout.buffer << ("<td c...
... ^~~
/Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:48: syntax error, unexpected `end', expecting ')'
...n</td>n</tr>n".freeze);; end;; _hamlout.buffer << ("<tr>...
... ^~~
/Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:58: syntax error, unexpected `ensure', expecting ')'
...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer....
... ^~~~~~
/Users/john/RubymineProjects/boulderweather/app/views/weather_station/index.html.haml:58: syntax error, unexpected `end', expecting ')'
...uffer.upper if @haml_buffer;end;
... ^~~
I encountered this error while I was trying to do the part with ‘accesing a current user’. I get the error on the code:
<nav class="navbar navbar-default">
<div class="container-fluid">
<%= link_to "Navbar", root_path, class="navbar-brand" %>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<%= link_to "Acasa", root_path, class="nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Medicamente", root_path, class="nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Afectiuni", root_path, class="nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Farmacii", root_path, class="nav-link" %>
</li>
</ul>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<% if Current.user %>
<li class="nav-item">
<span><%= Current.user.email, class="nav-link" %></span>
</li>
<li class="nav-item">
<%= button_to "Deconectare", logout_path, method: :delete, class="nav-link" %>
</li>
<% else %>
<li class="nav-item">
<%= link_to "Conectare", sign_in_path, class="nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Inregistrare", sign_up_path, class="nav-link" %>
</li>
<% end %>
</ul>
</div>
</div>
</nav>
and ruby says that the problem is on the line 16(shared/navbar) from the code that is posted downside but I had no ideea what the problem should be here. Can you guys help me with some ideas about this error? I will apreciatte a lot. TY.
<!DOCTYPE html>
<html>
<head>
<title>Myapp</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render partial: "shared/navbar" %>
<div class="container">
<%= render partial: "shared/flash" %>
<%= yield %>
</div>
</body>
</html>
#ruby-on-rails #ruby
#ruby-на-рельсах #ruby
Вопрос:
Мое приложение rails отлично работает в разработке. но когда я развертываю его в рабочей среде на VPS, страница не загружается.
когда я загружаю пейдж, проводя хвостом по бревну
tail -f /var/www/myapp/code/log/production.log
Я получаю сообщение об ошибке ниже
INFO -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] Started GET "/" for 27.0.0.1 at 2021-01-04 14:45:11 0000
INFO -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] Processing by DashboardController#index as HTML
INFO -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] Rendering dashboard/index.html.erb within layouts/application
INFO -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] Rendered dashboard/index.html.erb within layouts/application (Duration: 1.0ms | Allocations: 394)
INFO -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] Completed 500 Internal Server Error in 3ms (Allocations: 710)
FATAL -- : [1c740360-49a5-4920-9dfd-47673fbd4eee] ActionView::SyntaxErrorInTemplate (Encountered a syntax error while rendering template: check
Rails указывает мне на код для app / view / dashboard /index.html.erb, который показан ниже.
<br><br><br><br><br>
<section>
<div class="block center-text">
<header class="header-group">
<h3>Welcome to Igbo Progressive Union, Connecting Igbo's, around the world.</h3>
</header>
<div class="row">
<div class="col-md-12">
</div>
</div>
</div>
</section>
<%= flash_messages %>
<section id="welcome">
<!-- ======= Top banner ======= -->
<div class="jumbotron img-centre">
<div background: url("../images/welcomeimage.jpeg") >
<p>
<br><br><br><br><br><br><br><br>
<a class="btn btn-primary btn-lg" href="#about">Learn more</a>
</p>
</div>
</div>
</section>
<section id="about">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">About IPU</h3>
</div>
<div class="panel-body">
<table class="table-responsive">
<tbody>
<tr>
<td><a><%= image_tag "ipu_logo1.jpg", width:"auto", height:"200", alt="ipu_logo" %></a></td>
<td conspan="7">
<div class="well">
<p>We promote, protect and defend the interest of our members and their dependants around the world. We strive to create awareness of our culture and roots among ourselves and our children. Furthermore IPU promotes social interaction amongst the members of the community and and our members to enhance good relations between our Igbo community and other communities in Nigeria, United Kingdom, USA and throughout the world.</p>
</div>
</td>
<td><a><%= image_tag("IMG_6240.JPG", width:"auto", height:"200") %></a></td>
</tr>
</tbody>
</table>
<div class="well">
<p>Our goal is to continously promote Igbo language and culture (Omenani) everywhere in the world where Igbo's reside. We provide a common platform for Igbo's to engage in conversations concerning our culture and tradition, and share information to promote our ideologies. There are extended benefits for financial members, that include support in times of need, such as bereavement, child birth, hospitalization and many more. You can participate on our platform as a standard member at no extra cost by registering on our home page. If you enjoy what we are doing and want to support us, please make a voluntary contrubition to support our global efforts. However becoming a financial member, makes you eligible for all benefits and support as stated in our Articles of Association (constitution) as may be amended from time to time by the general assembley.</p>
</div>
</div>
</div>
</section>
<section id="objectives">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Objectives of IPU</h3>
</div>
<div class="panel-body">
<table class="table-responsive">
<tbody>
<tr>
<td>
<ol type="1">
<li>To promote brotherhood, friendship and unity amongst the Igbo community living in Northamptonshire, the United Kingdom, Nigeria, and throughout the world as well as integrating with other communities.</li>
<li>To support the welfare of IPU members whether that be morally, financially or otherwise in causes which in the opinion of the General Meeting merit the support of members.</li>
<li>To promote and create awareness of the Igbo Language and culture within Northamptonshire and the United Kingdom in general through cultural events, festivals, seminars, and speaking Igbo.</li>
<li>To organise lectures and educational trips about Igbo language, culture and heritage to the children of IPU members.</li>
<li>In accordance with Igbo tradition to observe “OMENANI” where appropriate to do so.</li>
</ol>
</td>
<td><a><%= image_tag("IMG_66131.JPG", width:"auto", height:"200") %></a></td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="contact">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Contact Us</h3>
</div>
<div class="panel-body">
<table class="table-responsive">
<tbody>
<tr>
<td><%= image_tag("IMG_62471.JPG", width:"auto", height:"200") %></td>
<td>
<p>Pastor </p>
<p>Phone: 44</p>
<br>
<p>Barr </p>
<p>Phone: 44</p>
<br>
<p>Gideon </p>
<p>Phone: 44</p>
<br>
<p>Chidi </p>
<p>Phone: 44</p>
<br>
<p>Kingsley </p>
<p>Phone: 44</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
Моя проблема в том, что я не могу найти никаких синтаксических ошибок. наконец, в довершение всего, ниже выбрасываются ошибки.
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:42: syntax error, unexpected ')', expecting =>
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:121: syntax error, unexpected `end', expecting ')'
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:42: syntax error, unexpected ')', expecting =>
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:121: syntax error, unexpected `end', expecting ')'
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:42: syntax error, unexpected ')', expecting =>
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:121: syntax error, unexpected `end', expecting ')'
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:42: syntax error, unexpected ')', expecting =>
[7897e223-644d-47ba-bc0c-1eb65772a76d] app/views/dashboard/index.html.erb:121: syntax error, unexpected `end', expecting ')'
однако у меня даже нет строки 121 в app/views/dashboard/index.html.erb:121, поскольку код завершается до этого в строке 119.
Как я могу найти эту синтаксическую ошибку ?. любые идеи будут приветствоваться. моя конфигурация рабочего сервера показана ниже
Ubuntu 20.04 Ruby 2.7.2 с RVM rvm 1.29.11 Веб-сервер: Пассажирский NGINX База данных: Mysql 8.0
Комментарии:
1. Идеальный. это было оно. большое вам спасибо. сделайте это ответом, чтобы я мог получить к нему доступ.
Ответ №1:
Это всего лишь небольшая опечатка:
<%= image_tag "ipu_logo1.jpg", width:"auto", height:"200", alt="ipu_logo" %>
Заменить alt=
на alt:
.
Do not use. This class is for internal use only.
Constant Summary
Class Method Summary
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(template, offending_code_string) ⇒ SyntaxErrorInTemplate
[ GitHub ]
# File 'actionview/lib/action_view/template/error.rb', line 233
def initialize(template, offending_code_string) @offending_code_string = offending_code_string super(template) end
Instance Method Details
#annotated_source_code
[ GitHub ]
# File 'actionview/lib/action_view/template/error.rb', line 244
def annotated_source_code @offending_code_string.split("n").map.with_index(1) { |line, index| indentation = " " * 4 "#{index}:#{indentation}#{line}" } end
#message
[ GitHub ]
# File 'actionview/lib/action_view/template/error.rb', line 238
def message <<~MESSAGE Encountered a syntax error while rendering template: check #{@offending_code_string} MESSAGE end
почему-то ошибка. Что не так?
Encountered a syntax error while rendering template: check div.card
h3 Sign In
p Login to manage your account
= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
div.js-form-message.mb-4
https://pastebin.com/xevCHTAR
russian
programming
ruby
8
ответов
Как минимум текст не везде в кавычках.
Nikolay Zhurilo
Как минимум текст не везде в кавычках.
А зачем его в кавычки? Простой же plain text в p
Artem
А зачем его в кавычки? Простой же plain text в p
Тогда встречный вопрос: зачем текст для submit в кавычках?
Nikolay Zhurilo
Тогда встречный вопрос: зачем текст для submit в к…
Так как присутствует Ruby code. Особенность языка Slim. Поправьте если не прав
Nikolay Zhurilo
Как минимум текст не везде в кавычках.
Я со slim не работал, но почитайте этот коммент. Если форму удалить или только форму оставить — что изменится?
Nikolay Zhurilo
Я со slim не работал, но почитайте этот коммент. Е…
Тоже ошибка, но там много завязано на отсупах
11 строчка — что за треш я вижу? Явно между 10 и 11 строчками какая-то проблема есть. Я с телефона смотрю, если что.
Kirill Ilyin
11 строчка — что за треш я вижу? Явно между 10 и 1…
Поочередно удаляю и скорее всего да, лишку обвешал. Спасибо
Мне нужно динамически загружать содержимое боковой панели в частичную боковую панель на основе наличия каталога, разделенного именами как controller_name
(если есть) и action_name
(всегда используется). Оба они получены из хэша Rails и сопоставляются с .../views/sidebars/[controller_name]/[action_name]
, если есть каталог для controller_name
, и с .../views/sidebars/[action_name]
, если нет связанного каталога с именем контроллера.
/views
/sidebars
/static
/_about.html.erb
/_contact.html.erb
/...
/_styles.html.erb #outside of any controller structure
Я пытаюсь использовать следующий код для динамической загрузки правильной части боковой панели:
<%= "sidebars/#{controller_name}".to_s.present? ? yield("sidebars/#{controller_name}/#{action_name}" : yield("sidebars/#{action_name}") %>
Это проверяет, существует ли каталог, вызываемый controller_name
, и отображает правильное частичное на основе указанной структуры.
Я получаю следующую ошибку:
Encountered a syntax error while rendering template: check <div id='sidebar_left'>
<p>Template: [_sidebar-left.html.erb]</p>
<%= render "sidebars/#{action_name}" %>
<%= "sidebars/#{controller_name}".to_s.present? ? yield("sidebars/#{controller_name}/#{action_name}" : yield("sidebars/#{action_name}") %>
< sizesUPDATE
Итак, получается, что тернарные операторы не всегда возвращают значение, особенно если это вычисляемое строковое значение. В этом случае я ожидал, что значение вернется как sidebars/static/home
или sidebars/styles
. По какой-то причине, которую я не могу объяснить, тернарные операторы так не работают, хотя я (думал!) возвращал строковое значение из операции.
Чтобы избавиться от синтаксической ошибки, мне пришлось присвоить оператор имени переменной, в данном случае sb_name
, а затем отобразить его на следующей строке. Это окончательный код:
<% sb_name = "sidebars/#{controller_name}".to_s.present? ? "sidebars/#{controller_name}/#{action_name}" : "sidebars/#{action_name}" %>
<%= render sb_name %>
Теперь, хотя это устранило синтаксическую ошибку, теперь я получаю ошибку Missing partial sidebars/_about
в представлении. Файл _styles
существует как /views/sidebars/_styles.html.erb
именно там, где и должен. Поскольку нет папки с именем вызываемого контроллера (в данном случае StylesController
), он должен подтягивать файл непосредственно под каталогом /sidebars/
. Однако, это не так.
1 ответ
Лучший ответ
Я нашел помощь в SO здесь. Я неправильно проверял структуру каталогов/файлов. Окончательный синтаксис таков:
<% sb_name = File.directory?("app/views/sidebars/#{controller_name}") ? "/sidebars/#{controller_name}/#{action_name}" : "/sidebars/#{action_name}" %>
<%= render partial: "#{sb_name}" %>
0
Matteo
28 Июл 2022 в 21:46