I am getting the following error while submitting the form.
Error:
ActiveRecord::StatementInvalid in SdfsController#create
Mysql::Error: Out of range value for column 'donation_amount' at row 1: INSERT INTO `t_sdfs` (`brahmin`, `created_at`, `created_by`, `date_of_death`, `deceased_address1`, `deceased_address2`, `deceased_block`, `deceased_country`, `deceased_dist`, `deceased_name`, `deceased_ps`, `deceased_state`, `deceased_village`, `donation_amount`, `donation_date`, `doner_address1`, `doner_address2`, `doner_block`, `doner_country`, `doner_dist`, `doner_mobileNo`, `doner_name`, `doner_ps`, `doner_relationship_id`, `doner_relationship_other`, `doner_state`, `doner_thumb`, `doner_video`, `doner_village`, `hcsy_status`, `photo1`, `photo2`, `receipt_no`, `updated_at`, `updated_by`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Rails.root: C:/Site/swargadwar_admin
Application Trace | Framework Trace | Full Trace
app/controllers/sdfs_controller.rb:10:in `create'
I am using carrierwave gem for photo uploading.Please check my below code files and try to help me to resolve this error.
views/sdfs/edit.html.erb
<center>
<%= form_for :sdf,:url => {:action => "create" } do |f| %>
<p>
<label for= "name">Deceased Name</label>
<%= f.text_field :deceased_name %>
</p>
<p>
<label for ="name">Deceased Address-1</label>
<%= f.text_field :deceased_address1 %>
</p>
<p>
<label for "name">Deceased Address-2</label>
<%= f.text_field :deceased_address2 %>
</p>
<p>
<label for ="name">Deceased Village</label>
<%= f.text_field :deceased_village %>
</p>
<p>
<label for= "name">Deceased Block</label>
<%= f.text_field :deceased_block %>
</p>
<p>
<label for ="name">Deceased Dist</label>
<%= f.text_field :deceased_dist %>
</p>
<p>
<label for ="name">Deceased State</label>
<%= f.text_field :deceased_state %>
</p>
<p>
<label for ="name">Deceased country</label>
<%= f.text_field :deceased_country %>
</p>
<p>
<label for= "name">Deceased PS</label>
<%= f.text_field :deceased_ps %>
</p>
<p>
<label for ="name">Date of Death</label>
<%= f.text_field :date_of_death,:id => "popupDatepicker" %>
</p>
<p>
<label for ="name">Doner Name</label>
<%= f.text_field :doner_name %>
</p>
<p>
<label for= "name">Doner mobile no</label>
<%= f.telephone_field :doner_mobileNo %>
</p>
<p>
<label for ="name">Doner relationship id</label>
<%= f.text_field :doner_relationship_id %>
</p>
<p>
<label for ="name">Other relation ship id</label>
<%= f.text_field :doner_relationship_other %>
</p>
<p>
<label for ="name">Doner Address-1</label>
<%= f.text_field :doner_address1 %>
</p>
<p>
<label for= "name">Doner Address-2</label>
<%= f.text_field :doner_address2 %>
</p>
<p>
<label for= "name">Doner Village</label>
<%= f.text_field :doner_village %>
</p>
<p>
<label for= "name">Doner Block</label>
<%= f.text_field :doner_block %>
</p>
<p>
<label for ="name">Doner Dist</label>
<%= f.text_field :doner_dist %>
</p>
<p>
<label for ="name">Doner State</label>
<%= f.text_field :doner_state %>
</p>
<p>
<label for= "name">Doner Country</label>
<%= f.text_field :doner_country %>
</p>
<p>
<label for= "name">Doner PS</label>
<%= f.text_field :doner_ps %>
</p>
<p>
<label for ="name">Donation Amount</label>
<%= f.text_field :donation_amount %>
</p>
<p>
<label for ="name">Donation date</label>
<%= f.text_field :donation_date ,:id => "popupDatepicker" %>
</p>
<p>
<label for= "name">Photo</label>
<%= f.file_field :photo1 %>
</p>
<p>
<label for ="name">Doner photo</label>
<%= f.file_field :photo2 %>
</p>
<p>
<label for="name">Bramhin</label>
<%= f.text_field :brahmin %>
</p>
<p>
<label for= "name">Created</label>
<%= f.number_field :created_by %>
</p>
<p>
<label for ="name">Updated</label>
<%= f.number_field :updated_by %>
</p>
<p>
<label for ="name">HCSY Status</label>
Yes:<%= f.radio_button :hcsy_status,'Yes',:checked => true %>
No: <%= f.radio_button :hcsy_status,'No' %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
</center>
controller/sdfs_controller.rb
class SdfsController < ApplicationController
def new
end
def edit
@sdf=TSdf.new
end
def create
@sdf=TSdf.new(params[:sdf])
if @sdf.save
flash[:notice]="Data saved successfully"
flash[:color]="valid"
redirect_to :action => 'new', :controller => "admins"
else
flash[:alert]="Data could not saved"
flash[:color]="invalid"
render 'edit'
end
end
end
model/t_sdf.rb
class TSdf < ActiveRecord::Base
attr_accessible :brahmin, :created_by, :date_of_death, :deceased_address1, :deceased_address2, :deceased_block, :deceased_country, :deceased_dist, :deceased_name, :deceased_ps, :deceased_state, :deceased_village, :donation_amount, :donation_date, :doner_address1, :doner_address2, :doner_block, :doner_country, :doner_dist, :doner_mobileNo, :doner_name, :doner_ps, :photo1, :doner_relationship_id, :doner_relationship_other, :doner_state, :doner_thumb, :doner_video, :doner_village, :hcsy_status, :photo2, :updated_by, :receipt_no
mount_uploader :Photo1, Photo1Uploader
mount_uploader :Photo2, Photo2Uploader
end
migration/20150407215437_create_t_sdf.rb
class CreateTSdfs < ActiveRecord::Migration
def change
create_table :t_sdfs do |t|
t.string :receipt_no
t.string :deceased_name
t.string :deceased_address1
t.string :deceased_address2
t.string :deceased_village
t.string :deceased_block
t.string :deceased_dist
t.string :deceased_state
t.string :deceased_country
t.string :deceased_ps
t.date :date_of_death
t.string :doner_name
t.string :doner_mobileNo
t.integer :doner_relationship_id
t.string :doner_relationship_other
t.string :doner_address1
t.string :doner_address2
t.string :doner_village
t.string :doner_block
t.string :doner_dist
t.string :doner_state
t.string :doner_country
t.string :doner_ps
t.decimal :donation_amount, :precision => 3, :scale => 2
t.datetime :donation_date
t.string :photo1
t.string :photo2
t.string :doner_thumb
t.string :doner_video
t.string :brahmin
t.boolean :hcsy_status
t.integer :created_by
t.integer :updated_by
t.timestamps
end
end
end
I also run rails generate uploader Photo1 and rails generate uploader Photo2 for uploading two photo.Please help me to resolve the above error.
Aucun commentaire:
Enregistrer un commentaire