我有以下表格
<%= form_for @contact, url: new_contact_path(@contact), remote: true do |f| %>
<%= f.text_field :name %>
<%= f.text_field :email %>
<%= f.text_field :phone %>
<%= f.text_field :message %>
<%= f.submit 'Send' %>
这是我的控制器contacts_controller.rb
def new
@contact = Contact.new
end
def create
unless contact_params.nil?
@contact = Contact.new contact_params
@contact.save
end
end
当我提交表单时出现错误
First argument in form cannot contain nil or be empty
我也试过这个
<%= form_for Contact.new, url: {controller: :contact,action: :create}, remote: true do |f| %>
但是遇到路由错误
这是我的rake routes
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
我的 route.rb 有
resources :contacts
更新 1
private
def contact_params
params.require(:contact).permit(:customer_id,:post_id,:name,:email,:phone,:message)
end