我有资源
resources :posts
所以,我写了
<%= link_to 'Изменить', edit_post_path(posts.id), method: :edit %>
然后打开网址:
http://178.62.102.154:3000/posts/3522/edit
并返回No route matches [POST] "/posts/3522/edit"
。但是然后我按下url并输入它打开。为什么它从第一次开放?
答案 0 :(得分:0)
你应该写下来:
<%= link_to 'Изменить', edit_post_path(posts.id), method: :get %>
method:
个选项将 HTTP 动词作为符号。
Resource routing允许您快速声明给定资源控制器的所有常用路由。而不是为
index
,show
,new
,edit
,create
,update
和destroy
操作声明单独的路线,资源丰富的路由在一行代码中声明它们:
resources :posts
上述代码使用所有其他操作创建,#edit
操作为:
# GET edit_post_url(:id => 1)
def edit
# return an HTML form for editing a specific post
end
如果您未传递method:
选项的值,则根据#link_to
文档默认为POST
..因此,您的代码会点击该链接使用POST
方法,但路由文件使用GET
方法定义了操作。这就是你在帖子中提到错误的原因。