I am currently building a small app with Sinatra and have run up against an issue saving form data to the mysql database. Firstly I can confirm that the connection to the database is working as I am logging into the app with twitter auth and it is saving dat into its table.
The form is simple
route: '/'
<form action="/create" method="post">
<p>
<label for="">Weight</label>
<input type="text" name="weight[amount]">
</p>
<p>
<input type="submit" id="">
</p>
</form>
The model looks like so
class Weight
include DataMapper::Resource
property :id, Serial, key: true
property :amount, Float
property :is_goal, Boolean, :default => false
property :created_at, DateTime, :required => true
belongs_to :user
end
DataMapper.finalize
DataMapper.auto_upgrade!
and the sinatra route is like this:
post '/create' do
@weight = Weight.create(params[:weight])
if @weight.save
flash[:success] = "Its all saved now"
redirect '/'
else
flash[:failure] = "I Didnt save!"
redirect '/'
end
end
Now for some reason every time I enter the form is comes back with the I didnt save
flash. Im sure this is an obvious thing but I juts cant see where Im going wrong anywhere.