Okay, one last time, and I tested something similar to your application this
time. It's much much simpler than we've been trending.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable
and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
has_one :wishlist
after_create :assign_wishlist
private
def assign_wishlist
self.update_attributes :wishlist => Wishlist.create(:user_id => self.id)
end
end
class Wishlist < ActiveRecord::Base
belongs_to :user
has_many :wishlist_items
end
Please give that a try, or at least delete my other helpful suggestions, which
didn't seem to work with a has_one relationship.
Walter
On Feb 10, 2012, at 11:24 AM, Christopher Jones wrote:
> I know that the correct user is being signed in because certain elements
> such as adding a product etc. get created based on who is signed in and
> therefore associates the id of the product with them so that they get
> displayed under the profile.
>
> The wishlist should be created when I create the user account but at the
> moment it doesn't do that, I have to click on a button to create the
> wishlist but my problem with doing that is that the button can be
> clicked multiple times which I don't want, I just want the user to be
> able to create one wishlist so my options are to either have it create
> on user creation or limit the button to one use per user but that is
> beyond me.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.