Guest User

Untitled

a guest
May 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. ## controller:
  2.  
  3. def create
  4. @service = Service.new(params[:service])
  5. @notigroups = Notificationgroupdetail.find(:all)
  6. @notigroups << ["None", "0"]
  7. @hosts = Host.find(:all).collect {|p| [p.name, p.id] }
  8. @hosts << ["None", "0"]
  9. if @service.save
  10. flash[:notice] = "Service has been added!"
  11. redirect_to :action => "index"
  12. else
  13. flash[:error] = "Could not add service. Check error messages."
  14. render :action => "new"
  15. end
  16. end
  17.  
  18. ## view:
  19. <div id="service-new">
  20. <% form_for :service, :url => { :action => "create" } do |f| %>
  21. <fieldset>
  22. <legend>Main</legend>
  23. <dl>
  24. <dt>Name</dt>
  25. <dd><%= f.text_field :name %> <%= error_message_on(:service, :name) %></dd>
  26. <dt>Host</dt>
  27. <dd><%= f.text_field :host %> <%= error_message_on(:service, :host) %></dd>
  28. <dt>Port</dt>
  29. <dd><%= f.text_field :port %> <%= error_message_on(:service, :port) %></dd>
  30. <dt>Protocol check</dt>
  31. <dd><%= f.select :type, getServiceTypes.sort %> <%= error_message_on(:service, :type) %></dd>
  32. <dt>Timeout (seconds)</dt>
  33. <dd><%= f.text_field :timeout, :value => "5" %> <%= error_message_on(:service, :timeout) %></dd>
  34. <dt>Max. response time (ms)</dt>
  35. <dd><%= f.text_field :maxres, :value => "250" %> <%= error_message_on(:service, :maxres) %></dd>
  36. <dt>Notification group</dt>
  37. <dd>
  38. <%= f.select :warninggroup, @notigroups %>
  39. <%= error_message_on(:service, :warninggroup) %>
  40. </dd>
  41. <dt>Link to host</dt>
  42. <dd>
  43. <%= f.select :linkedhost, @hosts %>
  44. <%= error_message_on(:service, :linkedhost) %>
  45. </dd>
  46. </dl>
  47. </fieldset>
  48.  
  49. <fieldset>
  50. <legend>Control</legend>
  51. <%= submit_tag %>
  52. </fieldset>
  53. <% end %>
  54. </div>
  55.  
  56. ## html output of the field that is complained about:
  57.  
  58. <dd><div class="fieldWithErrors"><select id="service_type" name="service[type]"><option value="ftp">FTP</option>
  59. <option value="http">HTTP</option>
  60. <option value="imap">IMAP</option>
  61. <option value="none">None</option>
  62. <option value="pop3">POP3</option>
  63. <option value="smtp">SMTP</option>
  64. <option value="ssh">SSH</option></select></div> <div class="formError">can't be blank</div></dd>
Add Comment
Please, Sign In to add comment