如何从 JavaScript 侦听器传递变量(id):
Gmaps.map.callback = function() {
...
...
google.maps.event.addListener(marker, 'click', function() {
var id = this.currentMarker;
alert(id);
});
}
}
到 ruby-on-rails 控制器中的实例变量 (@foo)
def create
@foo = ???
...
end
在视图(表单)中正确创建关系:
<%= form_for user.relationships.build(:followed_id => @foo.id) do |f| %>
<div><%= f.hidden_field :followed_id %></div>
<div class="actions"><%= f.submit "Follow" %></div>
<% end %>
谢谢!