On form submission, it's telling me that it was successfully created but it's not showing any data that was submitted. The database is empty. It's showing "null" values and the same on the actual screen where I should be able to edit the data. Here's a screenshot
Update: I think the problem is that it's making a GET request but I don't know how to fix it. Here's a screen shot of my server doing a get when I clicked the submit
Here's the set up
In the index action of results_controller.rb, I have
def index
@results = Result.all
@blob = Sex.new //==@blob = Sex.new is the one I'm focussing on...
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @results }
end
end
In views/results/index, I have the form
<`%= form_for(@blob) do |f| %>`
<div class="field">
<b>1. solicitor exam was fixed?:</b><br/>
<%= f.label(:solicitorcurve, "it was cooked") %>
<%= f.radio_button(:solicitorcurve, "t") %> </br>
</div>
<div class="field">
<%= f.label(:solicitorcurve, "no it was ok") %>
<%= f.radio_button(:solicitorcurve, "f") %>
</div>
<div class="field">
<%= f.label(:draftingteach, "i give the teaching a grade of _ on a scale of 1 to 6") %>
<%= f.select:draftingteach, 1..6 %> </br>
</div>
In the create action of sexes_controller.rb i have
def create
@sex = Sex.new(params[:blob])
respond_to do |format|
if @sex.save
format.html { redirect_to(@sex, :notice => 'Sex was successfully created.') }
format.xml { render :xml => @sex, :status => :created, :location => @sex }
else
format.html { render :action => "new" }
format.xml { render :xml => @sex.errors, :status => :unprocessable_entity }
end
end
end
In models/sex.rb, there is nothing...
class Sex < ActiveRecord::Base
end
And this is the set up of the database
It looks like the issue is that you're retrieving
params[:blob]
when you should be looking atparams[:sex]
.form_for
will create fields named after the class of the object. The instance variable name@blob
you're using is arbitrary.This is a good argument for why you probably want to name instance variables for what they are. Less confusion.