2015-04-07 39 views
0

您好,我使用Rails3製作一個表單時出現以下錯誤。在Ruby on Rails中獲取加載錯誤3

錯誤:

LoadError in SdfsController#edit 

Expected C:/Site/swargadwar_admin/app/models/t_sdf.rb to define T_sdf 
Rails.root: C:/Site/swargadwar_admin 

Application Trace | Framework Trace | Full Trace 
app/controllers/sdfs_controller.rb:6:in `edit' 

第二個錯誤:

ActiveRecord::StatementInvalid in SdfsController#create 

Mysql::Error: Out of range value for column 'Donation_Amount' at row 1: INSERT INTO `t_sdfs` (`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`, `Doner_Photo`, `Doner_Relationship_ID`, `Doner_Relationship_Other`, `Doner_State`, `Doner_Thumb`, `Doner_Video`, `Doner_Village`, `HCSY_Status`, `Photo`, `Updated_By`, `created_at`, `receipt_no`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
Rails.root: C:/Site/swargadwar_admin 

Application Trace | Framework Trace | Full Trace 
app/controllers/sdfs_controller.rb:10:in `create' 

我解釋我下面的代碼,請檢查這些,讓我知道它將如何解決。

模型/ 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, :Doner_Photo, :Doner_Relationship_ID, :Doner_Relationship_Other, :Doner_State, :Doner_Thumb, :Doner_Video, :Doner_Village, :HCSY_Status, :Photo, :Updated_By, :receipt_no 
    mount_uploader :Photo, PhotoUploader 
    mount_uploader :Doner_Photo, DonerPhotoUploader 
    end 

控制器/ sdfs_controller.rb

class SdfsController < ApplicationController 
    def new 

    end 
    def edit 
     @sdf=T_sdf.new 
    end 
    def create 
     @sdf=T_sdf.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 

視圖/ 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.date_field :Donation_Date %> 
    </p> 
    <p> 
     <label for= "name">Photo</label> 
     <%= f.file_field :Photo %> 
    </p> 
    <p> 
     <label for ="name">Doner photo</label> 
     <%= f.date_field :Doner_Photo %> 
    </p> 
    <p> 
     <label for="name">Bramhin</label> 
     <%= f.date_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> 

遷移/ 20150407215437_create_t_sdfs.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 => 0 
     t.datetime :Donation_Date 
     t.string :Photo 
     t.string :Doner_Photo 
     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 

請幫我解決這個錯誤。

回答

0

在您的控制器中,將該類名稱T_sdf更改爲TSdf

def edit 
    @sdf=TSdf.new 
end 
+0

嗨adoben你能幫我解決一個小錯誤,下面解釋。這個錯誤是在提交表單之後。 錯誤: 的ActiveRecord :: StatementInvalid在SdfsController#創建 應用程序/控制器/ sdfs_controller.rb:10:'創建」 請檢查我的更新後的模型文件,並嘗試幫助me.Thanks –

+0

肯定@ rajat_474,你可以給我以下resultes,params和TSdf.column_names –

+0

嗨,adoben,在你的幫助下,我成爲能夠解決我的第一個錯誤。我所有上面的代碼都是一樣的,但我再次編輯第二個錯誤。我也使用carrierwave寶石照片上傳,但我點擊提交按鈕這種類型的錯誤即將到來。請檢查我上面更新的錯誤。 –