/YYYY/MM/Title-Slug URL structure with Friendly_Id Solution Chokes on #new and #edit

老子叫甜甜 提交于 2019-12-02 07:41:53

Your error states:

No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id, :month, :year]

As you can see from your failing line, format.html { redirect_to post_path, notice: 'Post was successfully created.' }, you are calling post_path with no arguments.

Your route get '/:year/:month/:id', to: 'posts#show', as: 'post' expects a year, month, and id. This jives with your error message above.

To fix, simply supply the missing parameters, like so:

format.html { redirect_to post_path(@post.year, @post.month, @post), notice: 'Post was successfully created.' }

in update and create actions change:

format.html { redirect_to post_path, notice: 'Post was successfully ...' }

with

format.html { redirect_to @post, notice: 'Post was successfully ...' }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!