liping_312351 2008-07-14 08:07
浏览 258
已采纳

为什么rails2.1中的link_to无效

[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 生成的

  • 写回答

6条回答 默认 最新

  • superxielei 2008-07-14 09:54
    关注

    ruby script/gentrate scaffold user name:string
    这样???
    那是不会有问题的啊...
    rake db:migrate
    执行了吗?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化