Guest User

Untitled

a guest
May 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def create
  2. @user_id = params[:user_id]
  3. @idea_id = params[:idea_id]
  4.  
  5. if (Vote.find(:all, :conditions => {:user_id => @user_id, :idea_id => @idea.id}) .length > 0)
  6. render :text => "notwice"
  7. return
  8. end
  9.  
  10. @vote = Vote.new(:user_id => @user_id, :idea_id => @idea_id)
  11.  
  12. @vote_count = Idea.find(@idea_id).vote_count.to_i + 1
  13. # @vote_count = Idea.find(@idea_id).vote_count.to_i + (User.find(@user_id).ideas.vote_count )^1/2
  14.  
  15. @idea_change = Idea.find(@idea_id).update_attribute(:vote_count, @vote_count)
  16.  
  17. respond_to do |format|
  18. if @vote.save
  19. format.html { render :text => "true" }
  20. format.xml { render :xml => @vote, :status => :created, :location => @vote }
  21. else
  22. format.html { render :text => "false" }
  23. format.xml { render :xml => @vote.errors, :status => :unprocessable_entity }
  24. end
  25. end
  26. end
Add Comment
Please, Sign In to add comment