And even simpler:

  before_create :assign_wishlist
  
  private
  def assign_wishlist
    self.wishlist = Wishlist.create
  end

1.8.7-p352 :003 > User.create! :name => 'Bill', :email => 'b...@bill.co', 
:password => 'helpermethod', :password_confirmation => 'helpermethod'
 => #<User id: 5, name: "Bill", created_at: "2012-02-10 19:51:15", updated_at: 
"2012-02-10 19:51:15", email: "b...@bill.co", encrypted_password: 
"$2a$10$rq0MdN9T7ErRj3Iqlt/eNOA8t22BbXM1xGNTz5w6LxhY...", reset_password_token: 
nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, 
current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, 
last_sign_in_ip: nil> 
1.8.7-p352 :004 > _.wishlist
 => #<Wishlist id: 4, created_at: "2012-02-10 19:51:15", updated_at: 
"2012-02-10 19:51:15", user_id: 5> 
1.8.7-p352 :005 > 

Walter

On Feb 10, 2012, at 2:43 PM, Walter Lee Davis wrote:

> 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 rubyonrails-talk@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> rubyonrails-talk+unsubscr...@googlegroups.com.
>> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to