路线的ActionController :: RoutingError:没有路由匹配[POST] “/位置/新”
resources :locations, :only => [:new, :create]
控制器
class LocationsController < ApplicationController
def new
@location = Location.new
end
def create
@location = Location.new(location_params)
if @location.save
flash[:notice] = 'Created location successfully'
redirect_to new_location_path
else
flash[:notice] = 'Invalid information. Please try again'
render :new
end
end
private
def location_params
params.require(:location).permit(:name, :street, :city, :state)
end
end
错误消息,当我点击保存。
视图
<%= simple_form_for :locations do |form| %>
<%= form.input :name %>
<%= form.input :street %>
<%= form.input :city %>
<%= form.input :state %>
<%= form.submit 'Create location' %>
<% end %>
使用水豚测试,当我点击保存它创建了一个新的位置。我不太确定为什么它不知道邮政路线是什么,因为我有新的和创建的路线。如果我将一个binding.pry放在create方法的下面,它不会被调用。所以我的创建方法没有被某些原因调用。
编辑:
耙路线
locations POST /locations(.:format) locations#
new_location GET /locations/new(.:format) locations#new
似乎是其中的form_for和等的符号使用在网络上大量的示例代码。 – Lori