私は次のフォームを持っています
<%= 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