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
|
||||
|
||||
def index
|
||||
@mashes = Mash.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @mashes }
|
||||
end
|
||||
def redirect_to_new
|
||||
flash[:notice] = 'Sneaky pete.'
|
||||
redirect_to(:action => 'new')
|
||||
end
|
||||
|
||||
def show
|
||||
@mash = Mash.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @mash }
|
||||
end
|
||||
end
|
||||
alias_method :index, :redirect_to_new
|
||||
alias_method :show, :redirect_to_new
|
||||
|
||||
def new
|
||||
@map_a, @map_b = Map.rand(2)
|
||||
@ -25,7 +14,7 @@ class MashesController < ApplicationController
|
||||
:requester => request.remote_ip,
|
||||
:map_a => @map_a.id,
|
||||
:map_b => @map_b.id,
|
||||
:winner => 'a'
|
||||
:winner => @map_a.id
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
@ -34,47 +23,20 @@ class MashesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@mash = Mash.find(params[:id])
|
||||
end
|
||||
|
||||
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|
|
||||
if @mash.save
|
||||
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 }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.html { render :action => 'new' }
|
||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||
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
|
||||
|
@ -1,24 +1,24 @@
|
||||
<h1>New mash</h1>
|
||||
<h1>Mash the Maps!</h1>
|
||||
<p>Choose your fave.</p>
|
||||
|
||||
<% form_for(@mash) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<div id="map_a">
|
||||
<%= f.label :map_a %><br />
|
||||
<div id="map_a" class="mash-image">
|
||||
<%= f.label 'A' %><br />
|
||||
<%= f.hidden_field :map_a, :value => @map_a.id %>
|
||||
<image src="<%= url_for @map_a %>.png" />
|
||||
</div>
|
||||
<div id="map_b">
|
||||
<%= f.label :map_b %><br />
|
||||
<div id="map_b" class="mash-image">
|
||||
<%= f.label 'B' %><br />
|
||||
<%= f.hidden_field :map_b, :value => @map_b.id %>
|
||||
<image src="<%= url_for @map_b %>.png" />
|
||||
</div>
|
||||
<p>
|
||||
<%= f.select :winner, [['A', @map_a.id], ['B', @map_b.id]] %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :winner %><br />
|
||||
<%= f.text_field :winner %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.submit 'Create' %>
|
||||
<%= f.submit 'Mash' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user