Skip to content

Commit

Permalink
The plural of media is now media. Added a custom inflection to avoid …
Browse files Browse the repository at this point in the history
…'medium' land. Should finish Rails 3.0.5 upgrade. [concerto#132 state:resolved]
  • Loading branch information
bamnet committed Mar 17, 2011
1 parent 8ca337b commit cfdf353
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MediasController < ApplicationController
class MediaController < ApplicationController
def show
@media = Media.find(params[:id])
send_data @media.file_contents, :filename => @media.file_name, :type => @media.file_type, :disposition => 'inline'
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
# GET /templates/new.xml
def new
@template = Template.new
@template.medias.build
@template.media.build

respond_to do |format|
format.html # new.html.erb
Expand All @@ -36,16 +36,16 @@ def new
# GET /templates/1/edit
def edit
@template = Template.find(params[:id])
if(@template.medias.empty?)
@template.medias.build
if(@template.media.empty?)
@template.media.build
end
end

# POST /templates
# POST /templates.xml
def create
@template = Template.new(params[:template])
@template.medias.each do |media|
@template.media.each do |media|
media.key = "original"
end

Expand All @@ -65,7 +65,7 @@ def create
# PUT /templates/1.xml
def update
@template = Template.find(params[:id])
@template.medias.each do |media|
@template.media.each do |media|
media.key = "original"
end

Expand Down Expand Up @@ -98,7 +98,7 @@ def preview
require 'RMagick'

@template = Template.find(params[:id])
@media = @template.medias.original.first
@media = @template.media.original.first
@image = Magick::Image.from_blob(@media.file_contents).first
@height = @image.rows
@width = @image.columns
Expand Down
4 changes: 2 additions & 2 deletions app/models/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class Content < ActiveRecord::Base
belongs_to :kind
has_many :submissions, :dependent => :destroy
has_many :feeds, :through => :submissions
has_many :medias, :as => :attachable
has_many :media, :as => :attachable

accepts_nested_attributes_for :medias
accepts_nested_attributes_for :media
accepts_nested_attributes_for :submissions

#Validations
Expand Down
4 changes: 2 additions & 2 deletions app/models/graphic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Graphic < Content

#Validations
validates :duration, :numericality => { :greater_than => 0 }
validates :medias, :length => { :minimum => 1, :too_short => "At least 1 file is required." }
validates :media, :length => { :minimum => 1, :too_short => "At least 1 file is required." }

# Automatically set the kind for the content
# if it is new.
Expand All @@ -21,7 +21,7 @@ def render(options={})
# about the resizing, but this is a good first pass.
if options.key?(:width) && options.key?(:height)
require 'RMagick'
@media = self.medias.original.first
@media = self.media.original.first

image = Magick::ImageList.new
image.from_blob(@media.file_contents)
Expand Down
4 changes: 2 additions & 2 deletions app/models/template.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Template < ActiveRecord::Base
has_many :screens
has_many :medias, :as => :attachable
has_many :media, :as => :attachable
has_many :positions

accepts_nested_attributes_for :medias
accepts_nested_attributes_for :media

#Validations
validates :name, :presence => true
Expand Down
6 changes: 3 additions & 3 deletions app/views/contents/graphic/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
if @content.medias.empty?
@content.medias.build({:key=>"original"})
if @content.media.empty?
@content.media.build({:key=>"original"})
end
%>
<% if @content.errors.any? %>
Expand All @@ -18,7 +18,7 @@ end
<div class="field">
<label>Specify File</label>
<div class="fieldbox">
<%= form.fields_for :medias do |media| %>
<%= form.fields_for :media do |media| %>
<%= media.file_field :file %>
<%= media.hidden_field :key %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/contents/graphic/_render_default.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= image_tag media_path(content.medias.original.first), :alt => content.name %>
<%= image_tag media_path(content.media.original.first), :alt => content.name %>
2 changes: 1 addition & 1 deletion app/views/contents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
</p>


<%= link_to "Media", @content.medias.original.first %>
<%= link_to "Media", @content.media.original.first %>
<%= link_to 'Edit', edit_content_path(@content) %> |
<%= link_to 'Back', contents_path %>
2 changes: 1 addition & 1 deletion app/views/templates/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= f.check_box :is_hidden %>
</div>
<div class="field">
<%= f.fields_for :medias do |media| %>
<%= f.fields_for :media do |media| %>
<%= media.file_field :file %>
<% end %>
</div>
Expand Down
31 changes: 31 additions & 0 deletions app/views/templates/_import_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%= form_for(@template, :url => import_templates_path, :html => { :multipart => true }) do |f| %>
<% if @template.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@template.errors.count, "error") %> prohibited this template from being saved:</h2>
<ul>
<% @template.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= label_tag :package %><br />
<%= file_field_tag :package %>
</div>
<hr />
<div class="field">
<%= label_tag :image %><br />
<%= file_field_tag :image %>
</div>
<div class="field">
<%= label_tag :descriptor %><br />
<%= file_field_tag :descriptor %>
</div>


<div class="actions">
<%= f.submit("Import Template") %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/templates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= @template.is_hidden %>
</p>

<%= link_to "Media", @template.medias.original.first %>
<%= link_to "Media", @template.media.original.first %>
<%= link_to 'Edit', edit_template_path(@template) %> |
<%= link_to 'Back', templates_path %>
5 changes: 3 additions & 2 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
inflect.irregular 'media', 'media'
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Concerto::Application.routes.draw do
resources :medias, :only => [:show]
resources :media, :only => [:show]

resources :templates do
resources :positions
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20110317033903_rename_medias_to_media.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RenameMediasToMedia < ActiveRecord::Migration
def self.up
rename_table :medias, :media
end

def self.down
rename_table :media, :medias
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100629160714) do
ActiveRecord::Schema.define(:version => 20110317033903) do

create_table "contents", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -53,7 +53,7 @@
t.datetime "updated_at"
end

create_table "medias", :force => true do |t|
create_table "media", :force => true do |t|
t.integer "attachable_id"
t.string "attachable_type"
t.string "key"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/unit/graphic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class GraphicTest < ActiveSupport::TestCase
graphic = Graphic.new
assert graphic.invalid?
assert graphic.errors[:duration].any?
assert graphic.errors[:medias].any?
assert graphic.errors[:media].any?
end

#Verify the kind is getting auto-assigned
Expand Down

0 comments on commit cfdf353

Please sign in to comment.