我期待补丁请求,但收到的是 post
I am anticipating a patch request but am receiving a post instead
我在我的 edit.html.erb 上提交表单,它给我一个没有路由匹配的错误 [POST]“/grouponepostings/17/edit”。我在我的文档中使用了简单的表格,但不确定如何指定它是我寻求的补丁请求。
这里是routes.rb
Rails.application.routes.draw do
get "/", to: "pages#index"
get "/grouponepostings", to:"grouponepostings#index"
get '/grouponepostings/new', to: 'grouponepostings#new'
get "/grouponepostings/:id", to:"grouponepostings#show"
post '/grouponepages', to: 'grouponepostings#create'
get '/grouponepostings/:id/edit', to: 'grouponepostings#edit'
patch 'grouponepostings/:id/edit', to: 'grouponepostings#update'
end
这里edit.html.erb:
<%= simple_form_for :postings1314 do |r| %>
<div>
<%=r.label :firstName%>
<%=r.text_field :firstName%>
</div>
<div>
<%=r.label :lastName%>
<%=r.text_field :lastName%>
</div>
<div>
<%=r.label :age%>
<%=r.text_field :age%>
</div>
<div>
<%=r.label :bio%>
<%=r.text_field :bio%>
</div>
<div>
<%= r.submit %>
</div>
<%end%>
这里是 grouponepostings_controller.rb:
class GrouponepostingsController < ApplicationController
def index
@postings1314 = Grouponepage.all
end
def show
@posting1314singular = Grouponepage.find(params[:id])
end
def new
@postings1314 = Grouponepage.new
end
def create
page_params = params.require(:grouponepage).permit(:firstName, :lastName, :age, :bio)
@posting1314 = Grouponepage.new(page_params)
@posting1314.save
redirect_to '/grouponepostings'
end
def edit
@posting1314 = Grouponepage.find(params[:id])
end
def update
@posting1314 = Grouponepage.find(params[:id])
page_params = params.require(:grouponepage).permit(:firstName, :lastName, :age, :bio)
@posting1314.update(page_params)
redirect_to '/'
end
end
将路线更改为
Rails.application.routes.draw do
resources :grouponepostings # This will generate REST routes
root to: "pages#index" # This should be the last route
end
在 routes.rb:
patch 'grouponepostings/:id/edit', to: 'grouponepostings#update', as: :update_posting
在 edit.html.erb:
<%= simple_form_for @postings1314, url: update_posting_path, method: :patch do |r| %>
Please note that I also added @
to @postings1314
我在我的 edit.html.erb 上提交表单,它给我一个没有路由匹配的错误 [POST]“/grouponepostings/17/edit”。我在我的文档中使用了简单的表格,但不确定如何指定它是我寻求的补丁请求。
这里是routes.rb
Rails.application.routes.draw do
get "/", to: "pages#index"
get "/grouponepostings", to:"grouponepostings#index"
get '/grouponepostings/new', to: 'grouponepostings#new'
get "/grouponepostings/:id", to:"grouponepostings#show"
post '/grouponepages', to: 'grouponepostings#create'
get '/grouponepostings/:id/edit', to: 'grouponepostings#edit'
patch 'grouponepostings/:id/edit', to: 'grouponepostings#update'
end
这里edit.html.erb:
<%= simple_form_for :postings1314 do |r| %>
<div>
<%=r.label :firstName%>
<%=r.text_field :firstName%>
</div>
<div>
<%=r.label :lastName%>
<%=r.text_field :lastName%>
</div>
<div>
<%=r.label :age%>
<%=r.text_field :age%>
</div>
<div>
<%=r.label :bio%>
<%=r.text_field :bio%>
</div>
<div>
<%= r.submit %>
</div>
<%end%>
这里是 grouponepostings_controller.rb:
class GrouponepostingsController < ApplicationController
def index
@postings1314 = Grouponepage.all
end
def show
@posting1314singular = Grouponepage.find(params[:id])
end
def new
@postings1314 = Grouponepage.new
end
def create
page_params = params.require(:grouponepage).permit(:firstName, :lastName, :age, :bio)
@posting1314 = Grouponepage.new(page_params)
@posting1314.save
redirect_to '/grouponepostings'
end
def edit
@posting1314 = Grouponepage.find(params[:id])
end
def update
@posting1314 = Grouponepage.find(params[:id])
page_params = params.require(:grouponepage).permit(:firstName, :lastName, :age, :bio)
@posting1314.update(page_params)
redirect_to '/'
end
end
将路线更改为
Rails.application.routes.draw do
resources :grouponepostings # This will generate REST routes
root to: "pages#index" # This should be the last route
end
在 routes.rb:
patch 'grouponepostings/:id/edit', to: 'grouponepostings#update', as: :update_posting
在 edit.html.erb:
<%= simple_form_for @postings1314, url: update_posting_path, method: :patch do |r| %>
Please note that I also added
@
to@postings1314