我有以下代码:
/assets/javascripts/home.js.coffee.erb
jQuery ->
addClickListeners = ->
$(document).on 'click', '#add-chord-link', addChord
$(document).on 'click', '#remove-chord-link', removeChord
addChord = (e) ->
e.preventDefault()
console.log("<%= asset_path('rails.png') %>")
console.log("<%= link_to 'Sign up now!', '#' %>")
console.log('addChord clicked')
$('#chord-choices').append('addedChord')
removeChord = (e) ->
e.preventDefault()
$('#chord-choices select').last().remove()
console.log('removeChord clicked')
addClickListeners()
console.log("<%= asset_path('rails.png') %>")
is的控制台输出/assets/rails.png
,这是我所期望的。但是,每当我包含console.log("<%= link_to 'Sign up now!', '#' %>")
页面时,我都会在加载页面时收到错误消息:
undefined method `link_to' for #<#<Class:0x007f9095960938>:0x007f9095b78ab8>
为什么这不起作用?