Guest User

Untitled

a guest
Jun 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. ## controller
  2.  
  3. def create
  4. @state = State.new(params[:state])
  5. @state.tags.each {|tag| tag.destroy}
  6. @state.tags = params[:tags].map {|tag| Tag.find_by_id tag}
  7.  
  8. respond_to do |format|
  9. if @state.save
  10. flash[:notice] = 'State was successfully created.'
  11. format.html { redirect_to(@state) }
  12. format.xml { render :xml => @state, :status => :created, :location => @state }
  13. else
  14. format.html { render :action => "new" }
  15. format.xml { render :xml => @state.errors, :status => :unprocessable_entity }
  16. end
  17. end
  18. end
  19.  
  20.  
  21. ## error
  22.  
  23. ActiveRecord::StatementInvalid in StatesController#create
  24.  
  25. Mysql::Error: Duplicate entry '1' for key 'PRIMARY': INSERT INTO states_tags (`updated_at`, `tag_id`, `id`, `state_id`, `created_at`) VALUES ('2009-06-12 10:59:01', 1, 1, 18, '2009-06-12 10:59:01')
  26.  
  27. RAILS_ROOT: C:/rails/webstate
Add Comment
Please, Sign In to add comment