0

我在我的 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
4

2 回答 2

1

将路线更改为

Rails.application.routes.draw do
 resources :grouponepostings # This will generate REST routes
 root to: "pages#index" # This should be the last route
end

更多的

于 2018-08-25T21:14:19.783 回答
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

于 2018-08-26T00:23:54.303 回答