Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #IndependentRep.rb
- blongs_to :user
- #User.rb
- has_many :independent_reps
- ##Below belongs to rep_controller.rb
- def create
- @indie_rep = IndependentRep.new(params[:independent_rep])
- @user = User.new(params[:user])
- @user.permission_id = User::PERMISSIONS["indRep"]
- if @user.save # returns true
- @indie_rep.user_id = @user.id # does fine. In breakpointer, returns 18 (the id of @user)
- # User is:
- #
- #=> #<User:0x24c6bf4 @password=nil, @new_record_before_save=true, @new_record=false,
- # @errors=#<ActiveRecord::Errors:0x248c7ec @errors={}, @base=#<User:0x24c6bf4 ...>>, @attributes={"permission_id"=>2,
- # "username"=>"testo", "id"=>19, "independent_rep_id"=>0, "password_hash"=>"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
- # "email"=>""}>
- if @indie_rep.save # returns false @user.save also returns false if ran again
- flash[:notice] = 'Independent Representative was successfully created.'
- redirect_to :action => 'test'
- else
- @user.destroy
- flash[:notice] = 'Error in saving the Contact Information.'
- redirect_to :action => 'test'
- end
- else
- flash[:notice] = 'There has been an error.'
- render :action => 'test'
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement