Actually mashing maps now, but not handling form post-back or making it pretty
This commit is contained in:
92
rails/map-mash/app/controllers/maps_controller.rb
Normal file
92
rails/map-mash/app/controllers/maps_controller.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
class MapsController < ApplicationController
|
||||
# GET /maps
|
||||
# GET /maps.xml
|
||||
def index
|
||||
@maps = Map.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @maps }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.png do
|
||||
GoogleMapLocationFetcher.new.fetch([@map.name]) do |loc,image|
|
||||
dest = Rails.root.join("public/maps/#{@map.id}.png")
|
||||
FileUtils.mkdir_p(File.dirname(dest))
|
||||
|
||||
File.open(dest, 'w') do |f|
|
||||
f.write(image)
|
||||
end
|
||||
send_file(dest)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /maps/new
|
||||
# GET /maps/new.xml
|
||||
def new
|
||||
@map = Map.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @map }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /maps/1/edit
|
||||
def edit
|
||||
@map = Map.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /maps
|
||||
# POST /maps.xml
|
||||
def create
|
||||
@map = Map.new(params[:map])
|
||||
|
||||
respond_to do |format|
|
||||
if @map.save
|
||||
flash[:notice] = 'Map was successfully created.'
|
||||
format.html { redirect_to(@map) }
|
||||
format.xml { render :xml => @map, :status => :created, :location => @map }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @map.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /maps/1
|
||||
# PUT /maps/1.xml
|
||||
def update
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @map.update_attributes(params[:map])
|
||||
flash[:notice] = 'Map was successfully updated.'
|
||||
format.html { redirect_to(@map) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @map.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /maps/1
|
||||
# DELETE /maps/1.xml
|
||||
def destroy
|
||||
@map = Map.find(params[:id])
|
||||
@map.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(maps_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
@@ -19,13 +19,13 @@ class MashesController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
map_a, map_b = Map.rand(2)
|
||||
@map_a, @map_b = Map.rand(2)
|
||||
|
||||
@mash = Mash.new(
|
||||
:requestor => request.remote_ip,
|
||||
:map_a => map_a.id,
|
||||
:map_b => map_b.id,
|
||||
:winner => 0
|
||||
:requester => request.remote_ip,
|
||||
:map_a => @map_a.id,
|
||||
:map_b => @map_b.id,
|
||||
:winner => 'a'
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
|
2
rails/map-mash/app/helpers/maps_helper.rb
Normal file
2
rails/map-mash/app/helpers/maps_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module MapsHelper
|
||||
end
|
17
rails/map-mash/app/views/layouts/maps.html.erb
Normal file
17
rails/map-mash/app/views/layouts/maps.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title>Maps: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p style="color: green"><%= flash[:notice] %></p>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
16
rails/map-mash/app/views/maps/edit.html.erb
Normal file
16
rails/map-mash/app/views/maps/edit.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<h1>Editing map</h1>
|
||||
|
||||
<% form_for(@map) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name %><br />
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.submit 'Update' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Show', @map %> |
|
||||
<%= link_to 'Back', maps_path %>
|
20
rails/map-mash/app/views/maps/index.html.erb
Normal file
20
rails/map-mash/app/views/maps/index.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<h1>Listing maps</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
|
||||
<% @maps.each do |map| %>
|
||||
<tr>
|
||||
<td><%=h map.name %></td>
|
||||
<td><%= link_to 'Show', map %></td>
|
||||
<td><%= link_to 'Edit', edit_map_path(map) %></td>
|
||||
<td><%= link_to 'Destroy', map, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New map', new_map_path %>
|
15
rails/map-mash/app/views/maps/new.html.erb
Normal file
15
rails/map-mash/app/views/maps/new.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<h1>New map</h1>
|
||||
|
||||
<% form_for(@map) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name %><br />
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.submit 'Create' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', maps_path %>
|
8
rails/map-mash/app/views/maps/show.html.erb
Normal file
8
rails/map-mash/app/views/maps/show.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<p>
|
||||
<b>Name:</b>
|
||||
<%=h @map.name %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_map_path(@map) %> |
|
||||
<%= link_to 'Back', maps_path %>
|
@@ -4,16 +4,14 @@
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :requester %><br />
|
||||
<%= f.text_field :requester %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :map_a %><br />
|
||||
<%= f.text_field :map_a %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :map_b %><br />
|
||||
<%= f.text_field :map_b %>
|
||||
<div id="map_a">
|
||||
<%= f.label :map_a %><br />
|
||||
<image src="<%= url_for @map_a %>.png" />
|
||||
</div>
|
||||
<div id="map_b">
|
||||
<%= f.label :map_b %><br />
|
||||
<image src="<%= url_for @map_b %>.png" />
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :winner %><br />
|
||||
@@ -24,4 +22,4 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', mashes_path %>
|
||||
<%= link_to 'Back', mashes_path %>
|
||||
|
Reference in New Issue
Block a user