I am anticipating a patch request but am receiving a post instead

XXXOMEGA

New Member
#1
I am submitting the form on my edit.html.erb and it is giving me an error for No route matches [POST] "/grouponepostings/17/edit". I am using simple forms in my document and am not sure how to specify that it is a patch request I seek.
Here is routes.rb
Mã:
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
Here edit.html.erb:
Mã:
<%= 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%>
And here is grouponepostings_controller.rb:
Mã:
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
 

Admin

Administrator
Thành viên BQT
#2
On routes.rb:
Mã:
patch 'grouponepostings/:id/edit', to: 'grouponepostings#update', as: :update_posting
On edit.html.erb:
Mã:
<%= simple_form_for @postings1314, url: update_posting_path, method: :patch do |r| %>
Please note that I also added @ to @postings1314
 
Top