继续没有路由匹配进行编辑。尝试使用"编辑",现在:更新,但仍然没有运气

时间:2016-05-28 01:49:58

标签: ruby-on-rails ruby

ActionView::Template::Error (No route matches {:action=>"update", 
:controller=>"text_posts"}):

<h1><%= text_post.blog %></h1>
<%= form_tag do %>
<%= link_to "New Text Post", controller: "text_posts", action: "new" %>
<%= link_to "Edit", controller: "text_posts", action: "update" %>
<%= link_to "Delete", controller: "text_posts", action: "destroy" %>
<% end %>
<span class='likes pull-left'>


new_image_link GET     /image_links/new(.:format)      image_links#new

edit_image_link GET    /image_links/:id/edit(.:format) image_links#edit

image_link GET         /image_links/:id(.:format)      image_links#show

PATCH                 /image_links/:id(.:format)      image_links#update

PUT                   /image_links/:id(.:format)      image_links#update

DELETE               /image_links/:id(.:format)      image_links#destroy

text_posts GET       /text_posts(.:format)           text_posts#index

POST                 /text_posts(.:format)           text_posts#create

new_text_post GET    /text_posts/new(.:format)       text_posts#new

edit_text_post GET    /text_posts/:id/edit(.:format)  text_posts#edit

text_post GET         /text_posts/:id(.:format)       text_posts#show

PATCH                 /text_posts/:id(.:format)       text_posts#update

PUT                   /text_posts/:id(.:format)       text_posts#update

DELETE               /text_posts/:id(.:format)       text_posts#destroy

3 个答案:

答案 0 :(得分:3)

您可以这样做:

<%= link_to "Edit",  edit_text_post_path(text_post) %>

答案 1 :(得分:1)

  1. 由于您在routes.rb中使用资源(根据您提供的路线)。如果你想进入编辑页面,最好使用路径助手,记得在参数中提供你想要编辑的text_post:
  2. <%= link_to "Edit", edit_text_post_path(text_post) %>

    <%= link_to "Delete", text_post_path(text_post), :method => :delete %>

    1. 你写的方式就是你在routes.rb中有一些东西定义如下:
    2. match ':controller(/:action(/:id(.:format)))', :via => :all

      即便如此,你仍然必须给它想要编辑的text_post,因为它需要在url的末尾有一个id。所以应该是这样的:

      <%= link_to 'Edit', :controller => 'text_posts', :action => 'edit', :id => text_post %>

      <%= link_to 'Delete', :controller => 'text_posts', :action => 'destroy', :id => text_post %>

      1. 您无需将链接包装到form_tag中。
      2. 希望它有所帮助。

答案 2 :(得分:0)

试试这个.................

<h1><%= text_post.blog %></h1>
<%= link_to "New Text Post", new_text_post_path %>
<%= link_to "Edit", edit_text_post_path(text_post) %>
<%= link_to "Delete", text_post_path(text_post), method: :delete %>

希望这对你有用。