Guest User

Untitled

a guest
Apr 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #rails 2.02
  2. # problem is that after setting error message in the listing class... it doesnt show up in the flash in the controller method flash[:error]
  3.  
  4. class Desire < ActiveRecord::Base
  5.  
  6. attr_accessor :error_message
  7. has_many :listings
  8.  
  9. def after_create
  10. Listing.create(:desire_id => self.id)
  11. end
  12.  
  13. end
  14.  
  15. class Listing < ActiveRecord::Base
  16.  
  17. def after_create
  18. self.desire.error_message = "foo"
  19. end
  20. end
  21.  
  22. class DesiresController < ApplicationController
  23. def create
  24. @desire = Desire.new(params[:desire])
  25. @desire.user_id = current_user.id
  26. if @desire.save
  27. # current_user.desires << @desire
  28. debugger
  29. flash[:notice] = 'Desire was successfully created.'
  30. flash[:error] = @desire.error_message
  31. redirect_to :action => 'index'
  32. else
  33. render :action => 'new'
  34. end
  35. end
Add Comment
Please, Sign In to add comment