Rick Denatale wrote:
I think you want
map.resources :rushing_offenses, :collection => {:delete =>
:destroyall}
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Thanks Rick.
When I do this I get the following error:
Invalid HTTP method specified in route conditions: {:method=>
:destroyall} (Argument Error)
…
I just want to clarify that the page data exists at
localhost:3000/rushing_offenses
My index.html.erb file under views\rushing_offenses looks like:
Rushing Offense
Current Time is <%= Time.now.to_s(:long) %>
Statistics are compiled for the week beginning (<%=
Time.now.beginning_of_week.to_s(:long) %>) and ending (<%=
Time.now.end_of_week.to_s(:long) %>) |
<% @rushing_offenses.each do |rushing_offense| %>
<% end %>
Rank |
Name |
Games |
Carries |
Net |
Avg |
Tds |
Ydspg |
Wins |
Losses |
Ties |
<%=h rushing_offense.rank %> |
<%=h rushing_offense.name %> |
<%=h rushing_offense.games %> |
<%=h rushing_offense.carries %> |
<%=h rushing_offense.net %> |
<%=h rushing_offense.avg %> |
<%=h rushing_offense.tds %> |
<%=h rushing_offense.ydspg %> |
<%=h rushing_offense.wins %> |
<%=h rushing_offense.losses %> |
<%=h rushing_offense.ties %> |
<%= link_to ‘Destroy All’, :action => ‘destroyall’, :confirm => ‘Are you
sure?’, :method => :delete %>
============================
My routes look like:
ActionController::Routing::Routes.draw do |map|
map.resources :rushing_offenses
map.resources :rushing_offenses, :collection => { :destroyall =>
:delete }
map.resources :rushing_offenses, :collection => { :delete =>
:destroyall }
map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’
map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’
map.register ‘/register’, :controller => ‘users’, :action => ‘create’
map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’
map.resources :users
map.resource :session
map.root :controller => ‘page’
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end
=============================
My rushing_offenses_controller.rb file looks like:
class RushingOffensesController < ApplicationController
GET /rushing_offenses
GET /rushing_offenses.xml
def index
start_date = Time.now.beginning_of_week
end_date = Time.now.end_of_week
@rushing_offenses = RushingOffense.find(:all, :conditions =>
[‘compiled_on > ? and compiled_on < ?’, start_date, end_date])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @rushing_offenses }
end
end
GET /rushing_offenses/1
GET /rushing_offenses/1.xml
def show
@rushing_offense = RushingOffense.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @rushing_offense }
end
end
GET /rushing_offenses/new
GET /rushing_offenses/new.xml
def new
@rushing_offense = RushingOffense.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @rushing_offense }
end
end
GET /rushing_offenses/1/edit
def edit
@rushing_offense = RushingOffense.find(params[:id])
end
POST /rushing_offenses
POST /rushing_offenses.xml
def create
@rushing_offense = RushingOffense.new(params[:rushing_offense])
respond_to do |format|
if @rushing_offense.save
flash[:notice] = 'RushingOffense was successfully created.'
format.html { redirect_to(@rushing_offense) }
format.xml { render :xml => @rushing_offense, :status =>
:created, :location => @rushing_offense }
else
format.html { render :action => “new” }
format.xml { render :xml => @rushing_offense.errors, :status =>
:unprocessable_entity }
end
end
end
PUT /rushing_offenses/1
PUT /rushing_offenses/1.xml
def update
@rushing_offense = RushingOffense.find(params[:id])
respond_to do |format|
if @rushing_offense.update_attributes(params[:rushing_offense])
flash[:notice] = 'RushingOffense was successfully updated.'
format.html { redirect_to(@rushing_offense) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @rushing_offense.errors, :status =>
:unprocessable_entity }
end
end
end
DELETE /rushing_offenses/1
DELETE /rushing_offenses/1.xml
def destroy
@rushing_offense = RushingOffense.find(params[:id])
@rushing_offense.destroy
respond_to do |format|
format.html { redirect_to(rushing_offenses_url) }
format.xml { head :ok }
end
end
def destroyall
@rushing_offense = RushingOffense.destroy_all
# @rushing_offense = RushingOffense.delete_all (very speedy: delete
from rushing_offenses)
respond_to do |format|
format.html { redirect_to(rushing_offenses_url) }
format.xml { head :ok }
end
end
def date_range
start_date=params[:sd]
end_date=params[:ed]
@rushing_offense = RushingOffense.find(:all, :conditions =>
[‘created_at > ? and created_at < ?’, start_date, end_date])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @rushing_offenses }
end
end
end
======================================
I’m really not sure what I’m doing wrong. There are no other views
defined for this method (not sure if there has to be)…