beginner here. I'm building an interactive website through Cloud9 using a tutorial online. We are using bootstrap, javascript, ruby on rails, html, and scss. However, I am currently stuck. Whenever I click 'submit'...I get a Routing Error page. None of the information is stored in my db.
This is my /config/routes.rb
Rails.application.routes.draw do
root to: 'pages#home'
get 'about', to: 'pages#about'
resources :contacts
end
This is my /app/controllers/contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
if @contact.save
redirect_to new_contact_path, notice: "Message sent."
else
redirect_to new_contact_path, notice: "Error occured."
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
This is my /saasapp/app/views/contacts/new.html.erb
<div class="container">
<div class="row">
<h3 class="text-center">Contact Us</h3>
<div class="col-md-4 col-md-offset-4">
<%= flash[:notice] %>
<div class="well">
<%= form_for "contact" do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.text_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments %>
<%= f.text_area :comments, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
</div>
I followed the instructions exactly, and I have no idea what is wrong or what to change. Can someone help before I rip my hair out? haha
Aucun commentaire:
Enregistrer un commentaire