指定 /articles
为对应的 URL
[root@h202 blog]# bin/rake routes
Running via Spring preloader in process 13088
Prefix Verb URI Pattern Controller#Action
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index
[root@h202 blog]#
(这里的 /articles 明明对应两个方法,GET、POST ,有点不太明白,为什么这样指定就一定成了POST请求)
随便填写东西,提交
原因是 ArticlesController 中找不到对应的 create 方法
[root@h202 blog]# cat app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def new
end
end
[root@h202 blog]# vim app/controllers/articles_controller.rb
[root@h202 blog]# cat app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def new
end
def create
end
end
[root@h202 blog]#
重新提交一次
这回又是找不到模板,不过变成了找不到 create 模板
暂时不尝试去直接解决这个模板问题
我们将刚才获取到的内容直接反馈回来
修改create方法,直接打印获取到的参数
[root@h202 blog]# vim app/controllers/articles_controller.rb
[root@h202 blog]# cat app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def new
end
def create
render plain: params[:article].inspect
end
end
[root@h202 blog]#
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。