<input id="store_longitude" name="store[longitude]" size="30" type="text" />
[javascript文]
<script type="text/javascript">
document.getElementById("store_longitude").value = xxxx;
</script>
<input id="store_longitude" name="store[longitude]" size="30" type="text" />
<script type="text/javascript">
document.getElementById("store_longitude").value = xxxx;
</script>
map.enableScrollWheelZoom();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Maps JavaScript API Example - simple</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=aaaaa"
type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="map" style="width: 300px; height: 300px"></div>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.441944, -122.141944), 13);
}
GEvent.addListener(map, 'click', function(overlay, point) {
if (point) {
document.getElementById("show_x").innerHTML = point.x;
document.getElementById("show_y").innerHTML = point.y;
}
});
//]]>
</script>
<P id="show_x"></P>
<P id="show_y"></P>
</body>
</html>
<div id="map" style="width: 500px; height: 500px"></div>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(38, 138), 5);
map.disableDragging();
}
GEvent.addListener(map, 'click', function(overlay, point) {
if (point) {
alert("x = " + point.x + ", y = " + point.y);
map.openInfoWindow(point,
document.createTextNode("openInfoWindow Test"));
}
});
//]]>
</script>
(3)application.html.erbを編集。<!DOCTYPE html>
<html>
<head>
<title>Googlemap</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAABWYMASZTPMzQMXu2alSa6xTvcRCYKSpWpPqDL-sNMuxVdHFI_BTd8zF9kdpV97QhhvGd0NWsQckXsw"
type="text/javascript"></script>
</head>
<body>
<%= yield %>
</body>
</html>
(4)サーバ起動
cd file_column_test
rails plugin install git://github.com/tekin/file_column.git
--- file_column.rb.orig 2010-09-28 00:54:44.000000000 +0900
+++ file_column.rb 2010-09-28 00:55:12.000000000 +0900
@@ -594,7 +594,7 @@
# default options. You can override these with +file_column+'s +options+ parameter
DEFAULT_OPTIONS = {
- :root_path => File.join(RAILS_ROOT, "public"),
+ :root_path => File.join(Rails.root, "public"),
:web_root => "",
:mime_extensions => MIME_EXTENSIONS,
:extensions => EXTENSIONS,
class Entry < ActiveRecord::Base
file_column :image,
:root_path => "#{Rails.root}/public/store",
:web_root => "store/",
:magick => {
:versions => {
:thumb => { :crop => "1:1", :size => "50x50" },
:middle => "150x150>",
:large => "480x480>"
}
}
end
<%= form_for(@entry, :html => { :multipart => true }) do |f| %>
<% if @entry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@entry.errors.count, "error") %> prohibited this entry from being saved:</h2>
<ul>
<% @entry.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :image %><br />
<%= file_column_field "entry", "image" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @entry.name %>
</p>
<p>
<b>Image:</b>
<%= image_tag(url_for_image_column(@entry, "image", :middle)) if @entry.image %>
</p>
<%= link_to 'Edit', edit_entry_path(@entry) %> |
<%= link_to 'Back', entries_path %>
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @entry.name %>
</p>
<p>
<b>Image:</b>
<%= image_tag(url_for_image_column(@entry, "image", :middle)) if @entry.image %>
</p>
<%= link_to 'Edit', edit_entry_path(@entry) %> |
<%= link_to 'Back', entries_path %>