Feature #236 » 0001-Implements-feature-236-Installation-media-are-now-us.patch
app/controllers/medias_controller.rb | ||
---|---|---|
class MediasController < ApplicationController
|
||
def index
|
||
@medias = Media.all(:include => [:operatingsystem])
|
||
@medias = Media.all(:include => [:operatingsystems])
|
||
end
|
||
def new
|
app/models/media.rb | ||
---|---|---|
class Media < ActiveRecord::Base
|
||
belongs_to :operatingsystem
|
||
has_and_belongs_to_many :operatingsystems
|
||
has_many :hosts
|
||
validates_uniqueness_of :name, :scope => :operatingsystem_id
|
||
validates_uniqueness_of :path, :scope => :operatingsystem_id
|
||
validates_uniqueness_of :name
|
||
validates_uniqueness_of :path
|
||
validates_presence_of :name, :path
|
||
validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
|
||
validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//,
|
app/models/operatingsystem.rb | ||
---|---|---|
class Operatingsystem < ActiveRecord::Base
|
||
has_many :hosts
|
||
has_many :medias
|
||
has_and_belongs_to_many :ptables
|
||
has_and_belongs_to_many :architectures
|
||
has_and_belongs_to_many :puppetclasses
|
||
has_and_belongs_to_many :medias
|
||
validates_presence_of :major, :message => "Operating System version is required"
|
||
validates_presence_of :name
|
||
validates_numericality_of :major
|
app/views/medias/_form.html.erb | ||
---|---|---|
and <strong>$version</strong>, <strong>$major</strong> and <strong>$minor</strong> will be substituted for the version of the operating system.
|
||
</small>
|
||
<p>
|
||
<%= f.label :operatingsystem_id %><br />
|
||
<%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
|
||
<%= f.label :operatingsystems %><br />
|
||
<%= edit_habtm @media, Operatingsystem %>
|
||
</p>
|
||
<% unless @media.new_record? -%>
|
||
<p>Currently used by <%= @media.hosts.count %> hosts</p>
|
app/views/medias/index.html.erb | ||
---|---|---|
<th>Name</th>
|
||
<th>Path</th>
|
||
<th>Operatingsystem</th>
|
||
<th></th>
|
||
</tr>
|
||
<% for media in @medias %>
|
||
<tr>
|
||
<td><%= link_to h(media), edit_media_path(media) %></td>
|
||
<td><%=h media.path %></td>
|
||
<td><%=h media.operatingsystem %></td>
|
||
<td><%=h media.operatingsystems.to_sentence %></td>
|
||
<td><%= link_to "Destroy", media, :confirm => 'Are you sure?', :method => :delete %></td>
|
||
</tr>
|
||
<% end %>
|
db/migrate/20100522142706_remove_operatingsystem_id_from_medias.rb | ||
---|---|---|
class RemoveOperatingsystemIdFromMedias < ActiveRecord::Migration
|
||
def self.up
|
||
remove_column :medias, :operatingsystem_id
|
||
end
|
||
def self.down
|
||
add_column :medias, :operatingsystem_id, :integer
|
||
end
|
||
end
|
db/migrate/20100522143100_create_medias_operatingsystems.rb | ||
---|---|---|
class CreateMediasOperatingsystems < ActiveRecord::Migration
|
||
def self.up
|
||
create_table :medias_operatingsystems , :id => false do |t|
|
||
t.references :media, :null => false
|
||
t.references :operatingsystem, :null => false
|
||
end
|
||
end
|
||
def self.down
|
||
drop_table :medias_operatingsystems
|
||
end
|
||
end
|
test/fixtures/medias.yml | ||
---|---|---|
one:
|
||
name: CentOS 5.4
|
||
path: http://mirror.averse.net/centos/6.0/os/$arch
|
||
operatingsystem_id: 1
|