读书人

Rails3课程系列之四:Rails3入门(4)

发布时间: 2012-12-21 12:03:49 作者: rapoo

Rails3教程系列之四:Rails3入门(4)

文章出处:http://edgeguides.rubyonrails.org/getting_started.html

?

1. 显示一条Post

当你在index页面点击一条文章的链接时,它将指向一条类似 http://localhost:3000/posts/1 的地址。Rails是把它作为show动作资源来解释的,然后传递 1 作为 :id 的参数。下面是 show 动作:

?

def destroy  @post = Post.find(params[:id])  @post.destroy  respond_with @postend

?destroy方法将从数据库中移除相应的记录,然后浏览器将跳转到 index 页面。

?

?

读书人网 >网络基础

热点推荐