loc*_*boy 4 javascript haml ruby-on-rails
嗨,我有以下内容:
= link_to @place.name, '#', onclick: 'get_maps(#{@location_string});'
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试使用 Rails 变量参数链接到 javascript 调用,但由于某种原因,rails 变量@location_string没有被传递到其中包含该变量的 javascript 调用。目前它被渲染为字符串:
<a href="#" onclick="get_maps(#{@location_string});">3308 Kanaina Ave</a>
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题有什么想法吗?
小智 5
你需要输入:
= link_to @place.name, '#', :onclick => "get_maps('#{@location_string}');"
Run Code Online (Sandbox Code Playgroud)
onclick是link_to的一个参数。
get_maps 里面的参数应该放在 '' 里面。