我在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
答案 0 :(得分:1)
将路线更改为
Rails.application.routes.draw do
resources :grouponepostings # This will generate REST routes
root to: "pages#index" # This should be the last route
end
答案 1 :(得分:0)
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| %>
请注意,我还将
@
添加到了@postings1314