class EventsController < ApplicationController
def index
@events = Event.all
end
def new
@event = Event.new
end
def create
#params.permit!
@event = Event.new(event_params)
@event.save
redirect_to :action => :index
end
def show
@event = Event.find(params[:id])
end
def edit
@event = Event.find(params[:id])
end
def update
#params.permit!
@event = Event.find(params[:id])
@event.update_attributes(event_params)
redirect_to :action => :show, :id => @event
end
def destroy
@event = Event.find(params[:id])
@event.destroy
redirect_to :action => :index
end
private
def event_params
params.require(:event).permit(:id, :name, :description)
end
end
index.html.erb
<ul>
<% @events.each do |event| %>
<li>
<%= event.name %>
<%= link_to 'Show', :controller => 'events', :action => 'show', :id => event %>
<%= link_to 'Edit', :controller => 'events', :action => 'edit', :id => event %>
<%= link_to 'Delete', :controller => 'events', :action => 'destroy', :id => event %>
</li>
<% end %>
</ul>
<%= link_to 'New event', :controller => 'events', :action => 'new' %>
前面的 Show 和 Edit 正常 但是点击 Delete 的时候总是跳到 Show 的 Action 中 我的 route.rb Rails.application.routes.draw do resources :events
这个是什么原因?怎么能正常进入 destroy 的 action 中呢?