Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## form
- <div class="formp border">
- <label class="left">Height</label>
- <%= select :player, :feet, 1..7, {:include_blank => true} %> feet
- <%= select :player, :inches, 1..11, {:include_blank => true} %> inches
- </div>
- ## player_controller
- def update
- params[:player][:position_ids] ||= []
- @player = Player.find(params[:id])
- respond_to do |format|
- if @player.update_attributes(params[:player])
- flash[:notice] = 'Player was successfully updated.'
- format.html { redirect_to(@player) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @player.errors, :status => :unprocessable_entity }
- end
- end
- end
- ## player model
- before_update :convert_height
- def convert_height
- self.height = ((feet.to_f * 30.48.to_f) + (inches.to_f * 2.54.to_f)).to_f
- end
- # returns linked name to name field
- def name
- name = [ firstname, middlename, lastname ].compact.join(" ")
- end
- # calculates feet from cm and shows it in select box
- def feet
- find_feet = self.height.to_f / 30.48.to_f
- @feet = find_feet.to_i
- end
- # calculates inches from remainder and shows it in select box
- def inches
- find_inches = (self.height.to_f - (30.48.to_f * feet))
- calc_cm = find_inches.to_f / 2.54.to_f
- @inches = calc_cm.to_i
- end
Add Comment
Please, Sign In to add comment