def destroy
@dignity.destroy
end
क्षमा करें, यह कोड नहीं है, यह ठीक है कि मैं अभी कैसा महसूस कर रहा हूं। मुझे पता है कि डेविस पर शुरुआती प्रश्नों का एक टन है, मुझे लगता है कि मैंने लगभग हर एक को देखा।मेरा user_id शून्य क्यों है?
रेल वसीयत उपयोगकर्ता
मैं भी रेल 3 GeoKit प्लगइन, (यकीन नहीं चल रहा हूँ कि अगर है उत्पन्न:
मैं रेल 3. में एक बहुत ही सरल वसीयत सेटअप मैंने किया है प्रासंगिक, बस जानते हैं कि मेरे पास यह अन्य मॉडल है) इसलिए मेरे पास स्थान नामक एक और मॉडल है, और यह act_as_mappable है।
कोड पोस्ट करने से पहले, मूल समस्या यह है कि मुझे स्वत: वृद्धि के लिए user_id नहीं लग रहा है। यह मेरी समझ थी कि रेलवे जादू के थोड़ा सा मेरे लिए इसका ख्याल रखना चाहिए, अगर मैं स्थान श्रेणी में user_id नामक कॉलम जोड़ता हूं। (जो मैंने माइग्रेशन के माध्यम से किया था।) और उसके बाद बस has_many सेट है और इसके अनुसार संबंधित है। (नीचे देखें)
मुझे पता नहीं लगा कि user_id हमेशा शून्य क्यों है। क्या डेविस इंजन के तरीके के साथ इसका कुछ संबंध है? मुझे पूरा यकीन है कि मैंने इस तरह के एसोसिएशन को अतीत में उसी तरह काम किया है जब मैं डेविस का उपयोग नहीं कर रहा था।
user.rb:
class User < ActiveRecord::Base
has_many :locations
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
location.rb:
class AddUseridToLocation < ActiveRecord::Migration
def self.up
add_column :locations, :user_id, :integer
end
def self.down
remove_column :locations, :user_id
end
end
और अंत में, यहाँ स्कीमा है:
class Location < ActiveRecord::Base
belongs_to :user
attr_accessible :street_adress, :city, :state, :zip, :item, :user_id
acts_as_mappable :auto_geocode => true
def address
return "#{self.street_adress}, #{self.city}, #{self.state}, #{self.zip}, #{self.item}"
end
end
यहां प्रवास उस स्तंभ जोड़ा है। आरबी:
ActiveRecord::Schema.define(:version => 20110213035432) do
create_table "locations", :force => true do |t|
t.string "street_adress"
t.string "city"
t.string "state"
t.string "zip"
t.float "lat"
t.float "lng"
t.datetime "created_at"
t.datetime "updated_at"
t.string "item"
t.integer "user_id"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.string "remember_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
संपादित करें: मैं एक आरटीएफएम प्रतिक्रिया के साथ ठीक हूं, जब तक मैं सही दिशा में थोड़ा धक्का प्राप्त कर सकता हूं। मुझे संदेह है कि मुझे अपने स्थानों_controller.rb की निर्माण कार्रवाई में रेल कुछ बताने की ज़रूरत है? किसी ने मुझे बस थोड़ा संकेत दिया है!
मुझे बस इसे अपने स्थान.आरबी में जोड़ना चाहिए, मैंने 'attr_accessible' पर 'user_id' को जोड़ा है, बस इसे काम करने की कोशिश कर रहा है, यही कारण है कि, अगर आप सोच रहे थे ... – Kevin
कोड पोस्ट करें जहां आप स्थान बनाते हैं। –
स्थान तालिका वृद्धि में user_id क्यों होगा? यह नहीं होगा उपयोगकर्ता तालिका में आईडी वृद्धि होगी। – Zabba