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:

<h1>Rushing Offense</h1>
<h5>Current Time is <%= Time.now.to_s(:long)   %> </h5>

<table>
  <tr>
    <td><i>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)  %>)</i></td>
  </tr>
</table>

<br />

<table>
  <tr>
    <th>Rank</th>
    <th>Name</th>
    <th>Games</th>
    <th>Carries</th>
    <th>Net</th>
    <th>Avg</th>
    <th>Tds</th>
    <th>Ydspg</th>
    <th>Wins</th>
    <th>Losses</th>
    <th>Ties</th>
  </tr>

  <% @rushing_offenses.each do |rushing_offense| %>
    <tr>
      <td><%=h rushing_offense.rank %></td>
      <td><%=h rushing_offense.name %></td>
      <td><%=h rushing_offense.games %></td>
      <td><%=h rushing_offense.carries %></td>
      <td><%=h rushing_offense.net %></td>
      <td><%=h rushing_offense.avg %></td>
      <td><%=h rushing_offense.tds %></td>
      <td><%=h rushing_offense.ydspg %></td>
      <td><%=h rushing_offense.wins %></td>
      <td><%=h rushing_offense.losses %></td>
      <td><%=h rushing_offense.ties %></td>
    </tr>
  <% end %>
</table>

<br />

<%= 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)...

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to