我正在尝试将值user.skypeid
传递给html.erb中的javascript代码participants
。做正确的方法是什么?以下方法对我不起作用。
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.skypeid %></td>
<td><%= link_to 'Show', user_path(user) %></td>
<td>
<div id="SkypeButton_Call_aaa_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_aaa_1",
"participants": [user.skypeid]
});
</script>
</div>
</td>
</tr>
答案 0 :(得分:1)
您必须将其打印为嵌入式红宝石,并将其包装在引号内:
plot_glaciers <- function(keep_glaciers = TRUE) {
layers <- vector('list')
layers$land <- geom_point(data = ds1, aes(x = Sepal.Length, y = Sepal.Width), color = "red")
layers$def <- list(scale_x_continuous("Longitude", breaks = seq(3, 8, by = 0.5)),
scale_y_continuous("Latitude", breaks = seq(1,5, by = 1)),
theme_bw())
if (keep_glaciers) {
layers$glacier <- geom_point(data = ds2, aes(x = Sepal.Length, y = Sepal.Width), color = "blue")
}
ggplot() + layers
}
plot_glaciers(TRUE)
plot_glaciers(FALSE)
虽然您可以将脚本移到外面或移动到另一个文件:
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.skypeid %></td>
<td><%= link_to 'Show', user_path(user) %></td>
<td>
<div id="SkypeButton_Call_aaa_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_aaa_1",
"participants": ['<%= user.skypeid %>']
});
</script>
</div>
</td>
</tr>
<% end %>