Handling mash creation, removing some unnecessary controller methods, redirecting some others to :action => 'new'.
This commit is contained in:
parent
b1e17869b1
commit
70d0a835ed
@ -1,22 +1,11 @@
|
|||||||
class MashesController < ApplicationController
|
class MashesController < ApplicationController
|
||||||
|
def redirect_to_new
|
||||||
def index
|
flash[:notice] = 'Sneaky pete.'
|
||||||
@mashes = Mash.all
|
redirect_to(:action => 'new')
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.xml { render :xml => @mashes }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
alias_method :index, :redirect_to_new
|
||||||
@mash = Mash.find(params[:id])
|
alias_method :show, :redirect_to_new
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.xml { render :xml => @mash }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@map_a, @map_b = Map.rand(2)
|
@map_a, @map_b = Map.rand(2)
|
||||||
@ -25,7 +14,7 @@ class MashesController < ApplicationController
|
|||||||
:requester => request.remote_ip,
|
:requester => request.remote_ip,
|
||||||
:map_a => @map_a.id,
|
:map_a => @map_a.id,
|
||||||
:map_b => @map_b.id,
|
:map_b => @map_b.id,
|
||||||
:winner => 'a'
|
:winner => @map_a.id
|
||||||
)
|
)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@ -34,47 +23,20 @@ class MashesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
|
||||||
@mash = Mash.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@mash = Mash.new(params[:mash])
|
mash_params = params[:mash]
|
||||||
|
mash_params[:requester] = request.remote_ip
|
||||||
|
@mash = Mash.new(mash_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @mash.save
|
if @mash.save
|
||||||
flash[:notice] = 'Mash was successfully created.'
|
flash[:notice] = 'Mash was successfully created.'
|
||||||
format.html { redirect_to(@mash) }
|
format.html { redirect_to(:action => 'new') }
|
||||||
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
||||||
else
|
else
|
||||||
format.html { render :action => "new" }
|
format.html { render :action => 'new' }
|
||||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
|
||||||
@mash = Mash.find(params[:id])
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @mash.update_attributes(params[:mash])
|
|
||||||
flash[:notice] = 'Mash was successfully updated.'
|
|
||||||
format.html { redirect_to(@mash) }
|
|
||||||
format.xml { head :ok }
|
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
@mash = Mash.find(params[:id])
|
|
||||||
@mash.destroy
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to(mashes_url) }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
<h1>New mash</h1>
|
<h1>Mash the Maps!</h1>
|
||||||
|
<p>Choose your fave.</p>
|
||||||
|
|
||||||
<% form_for(@mash) do |f| %>
|
<% form_for(@mash) do |f| %>
|
||||||
<%= f.error_messages %>
|
<%= f.error_messages %>
|
||||||
|
|
||||||
<p>
|
<div id="map_a" class="mash-image">
|
||||||
<div id="map_a">
|
<%= f.label 'A' %><br />
|
||||||
<%= f.label :map_a %><br />
|
<%= f.hidden_field :map_a, :value => @map_a.id %>
|
||||||
<image src="<%= url_for @map_a %>.png" />
|
<image src="<%= url_for @map_a %>.png" />
|
||||||
</div>
|
</div>
|
||||||
<div id="map_b">
|
<div id="map_b" class="mash-image">
|
||||||
<%= f.label :map_b %><br />
|
<%= f.label 'B' %><br />
|
||||||
|
<%= f.hidden_field :map_b, :value => @map_b.id %>
|
||||||
<image src="<%= url_for @map_b %>.png" />
|
<image src="<%= url_for @map_b %>.png" />
|
||||||
</div>
|
</div>
|
||||||
|
<p>
|
||||||
|
<%= f.select :winner, [['A', @map_a.id], ['B', @map_b.id]] %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :winner %><br />
|
<%= f.submit 'Mash' %>
|
||||||
<%= f.text_field :winner %>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<%= f.submit 'Create' %>
|
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user