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风格紧密相关