Guest User

Untitled

a guest
Apr 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. ## form
  2.  
  3. <div class="formp border">
  4. <label class="left">Height</label>
  5. <%= select :player, :feet, 1..7, {:include_blank => true} %> feet
  6. <%= select :player, :inches, 1..11, {:include_blank => true} %> inches
  7. </div>
  8.  
  9. ## player_controller
  10.  
  11. def update
  12. params[:player][:position_ids] ||= []
  13. @player = Player.find(params[:id])
  14. respond_to do |format|
  15. if @player.update_attributes(params[:player])
  16. flash[:notice] = 'Player was successfully updated.'
  17. format.html { redirect_to(@player) }
  18. format.xml { head :ok }
  19. else
  20. format.html { render :action => "edit" }
  21. format.xml { render :xml => @player.errors, :status => :unprocessable_entity }
  22. end
  23. end
  24. end
  25.  
  26. ## player model
  27.  
  28. before_update :convert_height
  29.  
  30. def convert_height
  31. self.height = ((feet.to_f * 30.48.to_f) + (inches.to_f * 2.54.to_f)).to_f
  32. end
  33.  
  34. # returns linked name to name field
  35. def name
  36. name = [ firstname, middlename, lastname ].compact.join(" ")
  37. end
  38.  
  39. # calculates feet from cm and shows it in select box
  40. def feet
  41. find_feet = self.height.to_f / 30.48.to_f
  42. @feet = find_feet.to_i
  43. end
  44.  
  45. # calculates inches from remainder and shows it in select box
  46. def inches
  47. find_inches = (self.height.to_f - (30.48.to_f * feet))
  48. calc_cm = find_inches.to_f / 2.54.to_f
  49. @inches = calc_cm.to_i
  50. end
Add Comment
Please, Sign In to add comment