Guest User

Untitled

a guest
Jun 22nd, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. def update
  2. respond_to do |format|
  3. emitter_params = params[@emitter_name.to_sym].inject({}) do |memo, tuple|
  4. param_key, param_value = tuple # param_key = :fuel_efficiency_in_miles_per_gallon ; param_value = "10,000"
  5. memo.merge({param_key => param_key.sanitize_if_numeric})
  6. end
  7. if @emitter.update_attributes(emitter_params)
  8. format.html do
  9. flash[:notice] = "#{@emitter.name} was successfully updated."
  10. redirect_to(@emitter)
  11. end
  12. format.xml { head :ok }
  13. format.js { render :template => 'emitters/update' }
  14. else
  15. format.html do
  16. if @characteristic
  17. render :template => "characteristics/edit"
  18. else
  19. render :text => "there was an error updating the #{@emitter_name.humanize.downcase} object as a whole, but there is no general edit page right now"
  20. end
  21. end
  22. format.xml { render :xml => @emitter.errors, :status => :unprocessable_entity }
  23. format.js do # currently only used for renaming
  24. @emitter.name = @emitter.name_was if @emitter.name_changed? # this is kind of brittle
  25. render :template => 'emitters/update'
  26. end
  27. end
  28. end
  29. end
Add Comment
Please, Sign In to add comment