Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #IndependentRep.rb
  2.  
  3. blongs_to :user
  4.  
  5. #User.rb
  6.  
  7. has_many :independent_reps
  8.  
  9. ##Below belongs to rep_controller.rb
  10.  
  11.  
  12. def create
  13. @indie_rep = IndependentRep.new(params[:independent_rep])
  14. @user = User.new(params[:user])
  15. @user.permission_id = User::PERMISSIONS["indRep"]
  16.  
  17. if @user.save # returns true
  18. @indie_rep.user_id = @user.id # does fine. In breakpointer, returns 18 (the id of @user)
  19.  
  20. # User is:
  21. #
  22. #=> #<User:0x24c6bf4 @password=nil, @new_record_before_save=true, @new_record=false,
  23. # @errors=#<ActiveRecord::Errors:0x248c7ec @errors={}, @base=#<User:0x24c6bf4 ...>>, @attributes={"permission_id"=>2,
  24. # "username"=>"testo", "id"=>19, "independent_rep_id"=>0, "password_hash"=>"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
  25. # "email"=>""}>
  26.  
  27.  
  28. if @indie_rep.save # returns false @user.save also returns false if ran again
  29. flash[:notice] = 'Independent Representative was successfully created.'
  30. redirect_to :action => 'test'
  31. else
  32. @user.destroy
  33. flash[:notice] = 'Error in saving the Contact Information.'
  34. redirect_to :action => 'test'
  35. end
  36. else
  37. flash[:notice] = 'There has been an error.'
  38. render :action => 'test'
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement