Vagabondette Vagabondette - 2 months ago 6
Ruby Question

Rails form won't submit after adding Foundation

I added the Foundation-Rails gem to my app and now my form won't submit. There are no errors in the console, and it's triggering a new event, but instead of adding it to the database, it puts the form submission information into the URL bar. So, it looks like this:

http://localhost:3000/submissions/new?utf8=%E2%9C%93&authenticity_token=T9qweZClsZHL%2B6hzepcz%2BipG4W5p5VEzxO9PcB7FJ%2F6lun8wHVbvtGRe8JZC1rqay5DEMCm%2F06RzQh91G6cRGA%3D%3D&submission%5Bsubmission_link%5D=test&submission%5Blocation%5D=test&submission%5Bbedrooms%5D=0&submission%5Bbathrooms%5D=0&submission%5Bimg1%5D=asdf&submission%5Bimg2%5D=asdf&submission%5Bimg2%5D=asdf&commit=Create+Submission


Any idea why adding Foundation broke my form and how to fix it? It's literally the only thing I changed from last night until this morning.

The server log looks like this:

Started GET "/submissions/new" for ::1 at 2016-09-11 13:49:33 +0200
Processing by SubmissionsController#new as HTML
Rendered submissions/_form.html.erb (1.9ms)
Rendered submissions/new.html.erb within layouts/application (2.7ms)
Completed 200 OK in 65ms (Views: 64.8ms | ActiveRecord: 0.0ms)


Started GET "/submissions/new?utf8=%E2%9C%93&authenticity_token=bFFTEWjFXdAojQStCTMLMU2IzNch42jwKWB%2FZPi5G4SGMZxY5TYD9YcoXEgxcoJRrF7piWG56meezS9h%2FdstYg%3D%3D&submission%5Bsubmission_link%5D=asdfas&submission%5Blocation%5D=asdfa&submission%5Bbedrooms%5D=0&submission%5Bbathrooms%5D=0&submission%5Bimg1%5D=asd&submission%5Bimg2%5D=as&submission%5Bimg2%5D=ads&commit=Create+Submission" for ::1 at 2016-09-11 13:49:53 +0200
Processing by SubmissionsController#new as HTML
Parameters: {"utf8"=>"���", "authenticity_token"=>"bFFTEWjFXdAojQStCTMLMU2IzNch42jwKWB/ZPi5G4SGMZxY5TYD9YcoXEgxcoJRrF7piWG56meezS9h/dstYg==", "submission"=>{"submission_link"=>"asdfas", "location"=>"asdfa", "bedrooms"=>"0", "bathrooms"=>"0", "img1"=>"asd", "img2"=>"ads"}, "commit"=>"Create Submission"}
Rendered submissions/_form.html.erb (3.0ms)
Rendered submissions/new.html.erb within layouts/application (3.9ms)
Completed 200 OK in 67ms (Views: 65.9ms | ActiveRecord: 0.0ms)


My form code looks like this:

<form>

<%= form_for (@submission) do |submission| %>

<div class="row">
<div class="medium-6 columns">
<label>Listing Link
<%= submission.text_field :submission_link, placeholder: "Add the URL for the listing." %>
</label>
</div>
<div class="medium-6 columns">
<label>Location
<%= submission.text_field :location, placeholder: "City, Country" %>
</label>
</div>
</div>

<div class="row">
<div class="medium-6 columns">
<label>Bedrooms
<%= submission.select :bedrooms, ["0", "1", "2", "3+"]%>
</label>
</div>
<div class="medium-6 columns">
<label>Private Bathrooms
<%= submission.select :bathrooms, ["0", "1", "2", "3+"]%>
</label>
</div>
</div>

<div class="row">
<div class="medium-4 columns">
<label>Image 1
<%= submission.text_field :img1, placeholder: "http://i.imgur.com/bCd9Qwl.png?1" %>
</label>
</div>
<div class="medium-4 columns">
<label>Image 2
<%= submission.text_field :img2, placeholder: "http://i.imgur.com/bCd9Qwl.png?1" %>
</label>
</div>
<div class="medium-4 columns">
<label>Image 2
<%= submission.text_field :img2, placeholder: "http://i.imgur.com/bCd9Qwl.png?1" %>
</label>
</div>
</div>

<div class="row">
<div class="medium-12 columns">
<%= submission.submit %>
</div>
</div>

<% end %>

</form>


My controller:

class SubmissionsController < ApplicationController

def index
@submissions = Submission.all
end

def new
@submission = Submission.new
end

def create
@submission = Submission.new(submission_params)
if @submission.save
redirect_to @submission
else
render :new
end
end

private

def submission_params
params.require(:submission).permit(:submission_link, :title, :location, :bedrooms, :bathrooms, :img1, :img2, :img3)
end
end

Answer

You have a <form> tag before the form_for. Get rid of the HTML form tag, the form_for will insert the correct tag.