GoRailsチュートリアルの後に通知システムを構築しようとしています。それを構築するには、jsonファイルを使用します。これは、私がうまく管理しています。JSONターボリンクでエラーが発生しました
私はhtml要素をターゲットにするJSONファイルに次の行を持っていたまで、すべてがうまく機能している:あなたがいずれかを持っている場合
"<a class="dropdown-item" href='#{notification.url}'>#{notification.content.title}</a>"
魔女だから私turbolinks =>Error picture
については、このエラーを生成していますこれに対処するためのアドバイス、それは私の多くを助ける!
私のコード=
Notification.coffee(エラーがある):
class Notifications
constructor: ->
@notifications = $("[data-behaviour='notifications']")
@setup() if @notifications.length > 0
setup: ->
$.ajax({
url: "/notifications.json"
dataType: "JSON"
method: "GET"
success: @handleSuccess
})
handleSuccess: (data) =>
items = $.map data, (notification) ->
"<a class="dropdown-item" href='#{notification.url}'>#{notification.content.title}</a>"
$("[data-behaviour='notification-items']").html(items)
jQuery ->
new Notifications
ナビゲーションバービュー:
<li class="dropdown" data-behaviour="notifications">
<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown" id="dropdownMenu1" tata-toggle="dropdown" aria-haspopup="true" aria-expended="false"> <i class="fa fa-bell" aria-hidden="true" style="font-size: 25px;"></i></a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" data-behaviour="notification-items">
<li class="dropdown-item">
<a href="">Action1</a>
</li>
<li class="dropdown-item">
<a> Action2 </a>
</li>
</ul>
</li>
そしてボーナスのために、JSONファイル:
json.array! @notifications do |notification|
json.id notification.id
json.receiver notification.receiver.pseudo
json.sender notification.sender.pseudo
json.title notification.title
json.content notification.content.title
json.url group_path(notification.content.group, anchor: "post_iter(#{notification.content.id})")
end
質問の構文エラーとテキストとしてのエラーメッセージの原因となっている 'layout.html.erb'の実際のコードを含めます。ここの他のものはほとんど無関係です。 – max
こんにちは@max、あなたの答えのおかげで、レイアウトからのエラーはjs turbolinksを参照する行であり、エラーの原因となっている行は私がコーヒーファイルに追加した行です。 ( "