没有路线匹配{:action =>“edit”,:controller =>“posts”}
耙路线结果如下:
posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy
routes.rb文件中包含资源:帖子.
链接是:< li><%= link_to“New Post”,new_post_path%>< / li>
新的& PostsController中的编辑方法:
def new @post = Post.new end def edit @post = Post.find(params[:id]) end
我可以显示帖子,编辑帖子并删除帖子.但每当我想单击链接以创建新帖子时,就会发生错误.我无法弄清楚为什么new_post_path将导致’编辑’路径????
有人可以帮我吗?如果您需要更多代码,请告诉我.
谢谢!
更新
>添加_sidebar.html.erb(对不起格式,idk如何将它们保留为原始格式,外面有一些普通的nav,ul,li标签)
><%= link_to“Home”,root_path%>
><%= link_to“关于我”,about_path%>
<%if signed_in? %GT;
><%= link_to“New Post”,new_post_path%>
<%if @post%>
><%= link_to“编辑帖子”,edit_post_path%>
><%= link_to“删除帖子”,post_path(@ post),方法:“删除”,确认:“你确定要删除吗?” %GT;
<%end%>
><%= link_to“退出”,chulai_path,方法:“删除”%>
<%end%>
> new.html.erb
<%= form_for @post do | f | %GT;
< div class =“field”>
<%= f.text_field:title%>
< / DIV>
<div class="field"> <%= f.text_area :content, placeholder: "new post here..." %> </div> <div class="field"> <%= f.select :public, [['Public', true], ['Private', false]] %> </div> <%= f.submit "Post", class: "btn" %>
<%end%>
>我试过app.new_post_path,它显示/ posts / new,我想这很好.