restful风格简单理解

restful风格简单就是模仿HTTP协议post,put ,get,delete四种请求方法。

例子如下:

表单默认是post请求,link_to默认是get请求
controller articles
    index articles_url
    new new_article_url
    create articles_url(), :method=>:post
    edit edit_article_url(article.id)
    update  article_url(article.id), :method=>:put
    destory article_url(article.id), :method=>:delete
    show   article_url(article.id)
   
    controller article
    index article_index_url
    new new_article_url
    create article_index_url(), :method=>:post
    edit   edit_article_url()
    update  article_url(article.id), :method=>:put
    destory article_url(article.id), :method=>:delete
    show   article_url(article.id)


render和redirect_to区别

render既是渲染模板而不牵扯任何其他

如:<%=render "header"%>对应的是_header.html.erb

        render :layout=>false不使用模板,注:(layout代指模板)

        render"new"即是套用new.html.erb这个模板

redirect_to是重定向后面跟的是action方法

如:redirect_to new_user_url() 跳转到新建页面

      redirect_to  user_index_url()跳转到主页面

而redirect_to跟restful风格紧密相关

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值