[code="java"]<% for department in @departments %>
<%=h department.Name %>
<%=h department.Number %>
<%=h department.ParentID %>
<%=h department.Note %>
<%= link_to 'Show', department_path(department.ID) %>
<%= link_to 'Edit', edit_department_path(department.ID) %>
<%= link_to 'Destroy',department_path(department.ID), :confirm => 'Are you sure?', :method => :delete %>
<% end %>[/code]
这样的delete不起作用
[code="java"]<% for department in @departments %>
<%=h department.Name %>
<%=h department.Number %>
<%=h department.ParentID %>
<%=h department.Note %>
<%= link_to 'Show', department %>
<%= link_to 'Edit', edit_department_path(department) %>
<%= link_to 'Destroy',department, :confirm => 'Are you sure?', :method => :delete %>
<% end %>[/code]
这样三个都不行!
问:上面的代码行吗? 是不是rails2.1方式有变 或者数据库字段不行!
rails2.1 RESTful routes 哪里有资料
[b]问题补充:[/b]
map.resources :departments 已经设置!
就是http提交后没有处理就返回!
[b]问题补充:[/b]
class DepartmentsController < ApplicationController
# GET /departments
# GET /departments.xml
def index
@departments = Department.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @departments }
end
end
# GET /departments/1
# GET /departments/1.xml
def show
@department = Department.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @department }
end
end
# GET /departments/new
# GET /departments/new.xml
def new
@department = Department.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @department }
end
end
# GET /departments/1/edit
def edit
@department = Department.find(params[:id])
end
# POST /departments
# POST /departments.xml
def create
@department = Department.new(params[:department])
respond_to do |format|
if @department.save
flash[:notice] = 'Department was successfully created.'
format.html { redirect_to(@department) }
format.xml { render :xml => @department, :status => :created, :location => @department }
else
format.html { render :action => "new" }
format.xml { render :xml => @department.errors, :status => :unprocessable_entity }
end
end
end
# PUT /departments/1
# PUT /departments/1.xml
def update
@department = Department.find(params[:id])
respond_to do |format|
if @department.update_attributes(params[:department])
flash[:notice] = 'Department was successfully updated.'
format.html { redirect_to(@department) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @department.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /departments/1
# DELETE /departments/1.xml
def destroy
@department = Department.find(params[:id])
@department.destroy
respond_to do |format|
format.html { redirect_to(departments_url) }
format.xml { head :ok }
end
end
end
[b]问题补充:[/b]
上面是controller 本人刚学 谢谢热心的回答!受益匪浅
[b]问题补充:[/b]
代码是用Scaffolding 生成的