Skip to content

Commit

Permalink
Added netdb editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kelly committed Oct 8, 2010
1 parent ba09fed commit 77311f8
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
47 changes: 36 additions & 11 deletions app/controllers/netdbs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
class NetdbsController < ApplicationController
layout 'standard'
def index
@search = Netdb.search params[:search]
@netdbs = @search.paginate(:page => params[:page])
end

def new
@netdb = Netdb.new
end

def create
@netdb = Netdb.new(params[:netdb])
if @netdb.save
flash[:foreman_notice] = "Successfully created network database"
redirect_to netdbs_url
else
render :action => 'new'
end
end

def edit
@netdb = Netdb.find(params[:id])
end

active_scaffold :netdb do |config|
config.label = "Network Database"
config.actions = [:list,:delete, :search, :create, :show, :update]
config.columns = [:name, :address, :vendor, :servertype]
columns[:servertype].label = "Service"
list.sorting = {:name => 'ASC' }
config.columns[:vendor].form_ui = :select
config.columns[:servertype].form_ui = :select
def update
@netdb = Netdb.find(params[:id])
if @netdb.update_attributes(params[:netdb])
flash[:foreman_notice] = "Successfully updated network database"
redirect_to netdbs_url
else
render :action => 'edit'
end
end

# Deletes require a page update so as to show error messsages
config.delete.link.inline = false
def destroy
@netdb = Netdb.find(params[:id])
@netdb.destroy
flash[:foreman_notice] = "Successfully destroyed network database"
redirect_to netdbs_url
end
end
20 changes: 20 additions & 0 deletions app/views/netdbs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% form_for @netdb do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :address %><br />
<%= f.text_field :address %>
</p>
<p>
<%= f.label :vendor %><br />
<%= f.collection_select :vendor_id, Vendor.all, :id, :name %>
</p>
<p>
<%= f.label :servertype %><br />
<%= f.collection_select :servertype_id, Servertype.all, :id, :name %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
6 changes: 6 additions & 0 deletions app/views/netdbs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% title "Edit network database" %>

<%= render :partial => 'form' %>

<p><%= link_to "View all network databases", netdbs_path %></p>

26 changes: 26 additions & 0 deletions app/views/netdbs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% title "Network databases" %>

<table class="list">
<tr>
<th>Name</th>
<th>Address</th>
<th>Vendor</th>
<th>Service</th>
<th></th>
</tr>
<% for netdb in @netdbs %>
<tr class="<%= cycle("even", "odd") -%>">
<td><%=link_to h(netdb.name), edit_netdb_path(netdb)%></td>
<td><%=netdb.address%></td>
<td><%=netdb.vendor.name%></td>
<td><%=netdb.servertype.name%></td>
<td align="right">
<%= link_to "Destroy", netdb, :confirm => "Delete #{netdb.name}?", :method => :delete %>
</td>
</tr>
<% end %>
</table>
<%= page_entries_info @netdbs %>
<%= will_paginate @netdbs %>

<p><%= link_to "New network database", new_netdb_path %></p>
5 changes: 5 additions & 0 deletions app/views/netdbs/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% title "New Subnet" %>

<%= render :partial => 'form' %>

<p><%= link_to "Back to List", subnets_path %></p>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ActionController::Routing::Routes.draw do |map|
map.resources :subnets
map.resources :netdbs
end

0 comments on commit 77311f8

Please sign in to comment.