I'm rails noob. I have no idea where is problem. I cant save messages to database by help contact form. But I can save it by help "ContactForm.new" in rails console.
My contact_form_controller.rb is:
class ContactFormController < ApplicationController
def new
end
def create
@contact_form = ContactForm.create!(params[:contact_form])
@contact_form.save!
redirect_to root_path
end
def show
@contact_form = ContactForm.all
end
end
My contact_form.html.erb is:
<div class="all-banners-width">
<figure class="green-background">
<%= form_for :contact_form do |f| %>
<p>
<%= f.label :name %><br>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :phone %><br>
<%= f.text_field :phone %>
</p>
<p>
<%= f.label :email %><br>
<%= f.text_field :email %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_field :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</figure>
</div>
My DB migration file is:
class CreateContactForms < ActiveRecord::Migration
def change
create_table :contact_forms do |t|
t.string :name
t.string :phone
t.string :email
t.string :text
t.timestamps null: false
end
end
end
my routes.rb is:
Rails.application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :contact_forms, only: [:new, :create, :destroy]
root 'static_pages#home'
match '/', to: 'static_pages#home', via: 'post'
match '/manager', to: 'static_pages#manager', via: 'get'
match '/manager', to: 'sessions#create', via: 'post'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
There are not any errors, when I send a message via this form. Thanks