RuntimeError 即将到来 Rails 3
RuntimeError is coming in Rails 3
当我使用 Rails 3.
提交表单时出现以下错误
错误:
HcsysController#create 中的运行时错误
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Rails.root: C:/Site/swargadwar_admin
Application Trace | Framework Trace | Full Trace
app/controllers/hcsys_controller.rb:12:in `create'
请检查我的以下代码并尝试帮助我解决此错误。
views/hcsys/new_html.erb
<center>
<%= form_for :hcsy,:url => {:action => "create",:id => params[:id] } do |f| %>
<p>
<label for= "name">Deceased Name</label>
<%= f.text_field :dece_name %>
</p>
<p>
<label for ="name">Beneficiary name</label>
<%= f.text_field :beneficiary_name %>
</p>
<p>
<label for "name"> Address line -1</label>
<%= f.text_field :beneficiary_address1 %>
</p>
<p>
<label for "name"> Address line -2</label>
<%= f.text_field :beneficiary_address2 %>
</p>
<p>
<label for ="name"> Village</label>
<%= f.text_field :beneficiary_village %>
</p>
<p>
<label for= "name">Block</label>
<%= f.text_field :beneficiary_block %>
</p>
<p>
<label for ="name">Dist</label>
<%= f.text_field :beneficiary_dist %>
</p>
<p>
<label for ="name">State</label>
<%= f.text_field :beneficiary_state %>
</p>
<p>
<label for ="name">country</label>
<%= f.text_field :beneficiary_country %>
</p>
<p>
<label for= "name">Police station</label>
<%= f.text_field :beneficiary_ps %>
</p>
<p>
<label for= "name">Occupation</label>
<%= f.text_field :occupation %>
</p>
<p>
<label for ="name">BPL</label>
Yes: <%= f.radio_button :bpl,'Yes',:checked => true %>
No : <%= f.radio_button :bpl,'No' %>
</p>
<p>
<label for ="name">Date of Required</label>
<%= f.text_field :date_of_required,:id => "popupDatepicker" %>
</p>
<p>
<label for ="name">Recieved fund earlier</label>
Yes:<%= f.radio_button :recieved_fund_earlier,'Yes',:checked => true %>
No: <%= f.radio_button :recieved_fund_earlier,'No' %>
</p>
<p>
<label for= "name">Mobile no</label>
<%= f.telephone_field :mobile %>
</p>
<p>
<label for ="name">Previous reciept no</label>
<%= f.text_field :prev_receipt_no %>
</p>
<p>
<label for ="name">Previous amount recieved</label>
<%= f.text_field :prev_amount_recieved %>
</p>
<p>
<label for ="name">Goverment service</label>
<%= f.text_field :govt_service %>
</p>
<p>
<label for= "name">Business</label>
<%= f.text_field :business %>
</p>
<p>
<label for= "name">Land property</label>
<%= f.text_field :land_property %>
</p>
<p>
<label for= "name">Others</label>
<%= f.text_field :others %>
</p>
<p>
<label for ="name"> Amount Required</label>
<%= f.text_field :amount_required %>
</p>
<p>
<label for= "name">Photo</label>
<%= f.file_field :bphoto %>
</p>
<p>
<label for ="name">Doner photo</label>
<%= f.file_field :dphoto %>
</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">Brahmin</label>
Yes:<%= f.radio_button :brahmin,'Yes',:checked => true %>
No: <%= f.radio_button :brahmin,'No' %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
</center>
controller/hcsys_controller.rb
class HcsysController < ApplicationController
def new
@hcsy=Hcsy.new
end
def show
@hcsy=Hcsy.all
end
def create
@sdf=Sdf.find(params[:id])
@hcsy=Hcsy.new(params[:hcsy])
@hcsy.sdp_id=@sdp.id
if @hcsy.save
flash[:notice]="data has successfully saved"
flash[:color]="valid"
redirect_to :action => "new" ,:controller => "admins"
else
flash[:alert]="Data could not saved"
flash[:color]="invalid"
render 'new'
end
end
end
migrate/20150408170838_create_hcsies.rb
class CreateHcsies < ActiveRecord::Migration
def change
create_table :hcsies do |t|
t.integer :sdp_id
t.integer :receipt_no
t.string :dece_name
t.string :beneficiary_name
t.integer :beneficiary_relationship_id
t.string :beneficiary_relationship_other
t.string :beneficiary_address1
t.string :beneficiary_address2
t.string :beneficiary_village
t.string :beneficiary_block
t.string :beneficiary_dist
t.string :beneficiary_state
t.string :beneficiary_country
t.string :beneficiary_ps
t.string :mobile
t.string :occupation
t.boolean :bpl
t.string :govt_service
t.string :business
t.string :land_property
t.string :others
t.boolean :brahmin
t.decimal :amount_required, :precision => 8, :scale => 2
t.date :date_of_required
t.boolean :recieved_fund_earlier
t.string :prev_receipt_no
t.decimal :prev_amount_recieved, :precision => 8, :scale => 2
t.string :dphoto
t.string :bphoto
t.string :b_audio
t.string :b_thumb
t.integer :created_by
t.integer :updated_by
t.timestamps
end
end
end
model/hcsy.rb
class Hcsy < ActiveRecord::Base
attr_accessible :amount_required, :b_audio, :b_thumb, :beneficiary_address1, :beneficiary_address2, :beneficiary_block, :beneficiary_country, :beneficiary_dist, :beneficiary_name, :beneficiary_ps, :beneficiary_relationship_id, :beneficiary_relationship_other, :beneficiary_state, :beneficiary_village, :bphoto, :bpl, :brahmin, :business, :created_by, :date_of_required, :dece_name, :dphoto, :govt_service, :land_property, :mobile, :occupation, :others, :prev_amount_recieved, :prev_receipt_no, :receipt_no, :recieved_fund_earlier, :sdp_id, :updated_by
mount_uploader :bphoto, BphotoUploader
mount_uploader :dphoto, DphotoUploader
belongs_to :sdf
end
请帮帮我。
将 @hcsy.sdp_id=@sdp.id
更改为 @hcsy.sdp_id=@sdf.id
... 只是 @sdf.id
当我使用 Rails 3.
提交表单时出现以下错误错误:
HcsysController#create 中的运行时错误
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Rails.root: C:/Site/swargadwar_admin
Application Trace | Framework Trace | Full Trace
app/controllers/hcsys_controller.rb:12:in `create'
请检查我的以下代码并尝试帮助我解决此错误。
views/hcsys/new_html.erb
<center>
<%= form_for :hcsy,:url => {:action => "create",:id => params[:id] } do |f| %>
<p>
<label for= "name">Deceased Name</label>
<%= f.text_field :dece_name %>
</p>
<p>
<label for ="name">Beneficiary name</label>
<%= f.text_field :beneficiary_name %>
</p>
<p>
<label for "name"> Address line -1</label>
<%= f.text_field :beneficiary_address1 %>
</p>
<p>
<label for "name"> Address line -2</label>
<%= f.text_field :beneficiary_address2 %>
</p>
<p>
<label for ="name"> Village</label>
<%= f.text_field :beneficiary_village %>
</p>
<p>
<label for= "name">Block</label>
<%= f.text_field :beneficiary_block %>
</p>
<p>
<label for ="name">Dist</label>
<%= f.text_field :beneficiary_dist %>
</p>
<p>
<label for ="name">State</label>
<%= f.text_field :beneficiary_state %>
</p>
<p>
<label for ="name">country</label>
<%= f.text_field :beneficiary_country %>
</p>
<p>
<label for= "name">Police station</label>
<%= f.text_field :beneficiary_ps %>
</p>
<p>
<label for= "name">Occupation</label>
<%= f.text_field :occupation %>
</p>
<p>
<label for ="name">BPL</label>
Yes: <%= f.radio_button :bpl,'Yes',:checked => true %>
No : <%= f.radio_button :bpl,'No' %>
</p>
<p>
<label for ="name">Date of Required</label>
<%= f.text_field :date_of_required,:id => "popupDatepicker" %>
</p>
<p>
<label for ="name">Recieved fund earlier</label>
Yes:<%= f.radio_button :recieved_fund_earlier,'Yes',:checked => true %>
No: <%= f.radio_button :recieved_fund_earlier,'No' %>
</p>
<p>
<label for= "name">Mobile no</label>
<%= f.telephone_field :mobile %>
</p>
<p>
<label for ="name">Previous reciept no</label>
<%= f.text_field :prev_receipt_no %>
</p>
<p>
<label for ="name">Previous amount recieved</label>
<%= f.text_field :prev_amount_recieved %>
</p>
<p>
<label for ="name">Goverment service</label>
<%= f.text_field :govt_service %>
</p>
<p>
<label for= "name">Business</label>
<%= f.text_field :business %>
</p>
<p>
<label for= "name">Land property</label>
<%= f.text_field :land_property %>
</p>
<p>
<label for= "name">Others</label>
<%= f.text_field :others %>
</p>
<p>
<label for ="name"> Amount Required</label>
<%= f.text_field :amount_required %>
</p>
<p>
<label for= "name">Photo</label>
<%= f.file_field :bphoto %>
</p>
<p>
<label for ="name">Doner photo</label>
<%= f.file_field :dphoto %>
</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">Brahmin</label>
Yes:<%= f.radio_button :brahmin,'Yes',:checked => true %>
No: <%= f.radio_button :brahmin,'No' %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
</center>
controller/hcsys_controller.rb
class HcsysController < ApplicationController
def new
@hcsy=Hcsy.new
end
def show
@hcsy=Hcsy.all
end
def create
@sdf=Sdf.find(params[:id])
@hcsy=Hcsy.new(params[:hcsy])
@hcsy.sdp_id=@sdp.id
if @hcsy.save
flash[:notice]="data has successfully saved"
flash[:color]="valid"
redirect_to :action => "new" ,:controller => "admins"
else
flash[:alert]="Data could not saved"
flash[:color]="invalid"
render 'new'
end
end
end
migrate/20150408170838_create_hcsies.rb
class CreateHcsies < ActiveRecord::Migration
def change
create_table :hcsies do |t|
t.integer :sdp_id
t.integer :receipt_no
t.string :dece_name
t.string :beneficiary_name
t.integer :beneficiary_relationship_id
t.string :beneficiary_relationship_other
t.string :beneficiary_address1
t.string :beneficiary_address2
t.string :beneficiary_village
t.string :beneficiary_block
t.string :beneficiary_dist
t.string :beneficiary_state
t.string :beneficiary_country
t.string :beneficiary_ps
t.string :mobile
t.string :occupation
t.boolean :bpl
t.string :govt_service
t.string :business
t.string :land_property
t.string :others
t.boolean :brahmin
t.decimal :amount_required, :precision => 8, :scale => 2
t.date :date_of_required
t.boolean :recieved_fund_earlier
t.string :prev_receipt_no
t.decimal :prev_amount_recieved, :precision => 8, :scale => 2
t.string :dphoto
t.string :bphoto
t.string :b_audio
t.string :b_thumb
t.integer :created_by
t.integer :updated_by
t.timestamps
end
end
end
model/hcsy.rb
class Hcsy < ActiveRecord::Base
attr_accessible :amount_required, :b_audio, :b_thumb, :beneficiary_address1, :beneficiary_address2, :beneficiary_block, :beneficiary_country, :beneficiary_dist, :beneficiary_name, :beneficiary_ps, :beneficiary_relationship_id, :beneficiary_relationship_other, :beneficiary_state, :beneficiary_village, :bphoto, :bpl, :brahmin, :business, :created_by, :date_of_required, :dece_name, :dphoto, :govt_service, :land_property, :mobile, :occupation, :others, :prev_amount_recieved, :prev_receipt_no, :receipt_no, :recieved_fund_earlier, :sdp_id, :updated_by
mount_uploader :bphoto, BphotoUploader
mount_uploader :dphoto, DphotoUploader
belongs_to :sdf
end
请帮帮我。
将 @hcsy.sdp_id=@sdp.id
更改为 @hcsy.sdp_id=@sdf.id
... 只是 @sdf.id