def destroy @dignity.destroy end
Sorry, this is not a code, this is how I feel right now. I know that there are a ton of newcomers to Devise, I think I looked at almost everyone.
I have a very simple Devise setup in Rails 3. I did:
rails are created by the developer
I also run the rails 3 GeoKit plugin (not sure if this is important, just know that I have this other model), so I have another model called Location and it acts_as_mappable.
Before posting the code, the main problem is that I cannot get user_id to increase automatically. I realized that a bit of Rails magic should take care of this for me if I add the user_id column to the Location class. (which I did with migration.) and then just set has_many and belongs accordingly. (see below)
I cannot understand why user_id is always null. Is this related to how the Devise engine works? I am sure that in the past I did similar associations work the same way when I did not use Devise.
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 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
here is the migration that added the column:
class AddUseridToLocation < ActiveRecord::Migration def self.up add_column :locations, :user_id, :integer end def self.down remove_column :locations, :user_id end end
And finally, here is the schema.rb schema:
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
EDIT: I'm fine with the RTFM answer, so far I can push a little in the right direction. I have a suspicion that I need to say rails something in the create action of my_controller.rb? Someone just give me a little hint here!