Skip to content

Commit

Permalink
Attachment conflict !��!
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed May 9, 2009
1 parent 87c54ba commit 9a741ff
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 435 deletions.
85 changes: 0 additions & 85 deletions app/controllers/attachments_controller.rb

This file was deleted.

85 changes: 85 additions & 0 deletions app/controllers/medias_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class MediasController < ApplicationController
# GET /medias
# GET /medias.xml
def index
@medias = Media.search(params[:filter],params[:page])

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @medias }
end
end

# GET /medias/1
# GET /medias/1.xml
def show
@media = Media.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @media }
end
end

# GET /medias/new
# GET /medias/new.xml
def new
@media = Media.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @media }
end
end

# GET /medias/1/edit
def edit
@media = Media.find(params[:id])
end

# POST /medias
# POST /medias.xml
def create
@media = Media.new(params[:media])

respond_to do |format|
if @media.save
flash[:notice] = 'Media was successfully created.'
format.html { redirect_to(@media) }
format.xml { render :xml => @media, :status => :created, :location => @media }
else
format.html { render :action => "new" }
format.xml { render :xml => @media.errors, :status => :unprocessable_entity }
end
end
end

# PUT /medias/1
# PUT /medias/1.xml
def update
@media = Media.find(params[:id])

respond_to do |format|
if @media.update_attributes(params[:media])
flash[:notice] = 'Media was successfully updated.'
format.html { redirect_to(@media) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @media.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /medias/1
# DELETE /medias/1.xml
def destroy
@media = Media.find(params[:id])
@media.destroy

respond_to do |format|
format.html { redirect_to(medias_url) }
format.xml { head :ok }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module AttachmentsHelper
module MediasHelper
def choose_icon(mime_type)
case mime_type
when /\.doc|odf|txt/ then "xls.png"
Expand Down
2 changes: 1 addition & 1 deletion app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
class Article < ActiveRecord::Base
belongs_to :user
has_many :attachments, :as => :attachable
has_many :medias, :as => :attachable
has_friendly_id :title, :use_slug => true

validates_presence_of :user
Expand Down
20 changes: 20 additions & 0 deletions app/models/holder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009 Fireho
#
# This file is part of SIGA.
#
# SIGA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SIGA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
class Holder < ActiveRecord::Base
attr_writer :person_text
belongs_to :group
Expand Down
12 changes: 6 additions & 6 deletions app/models/attachment.rb → app/models/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
class Attachment < ActiveRecord::Base
class Media < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
has_attached_file :media,
:styles => { :thumb => ["200x200#", :png] },
:path => ':rails_root/public/files/attachments/:id/:style/:basename.:extension',
:url => '/files/attachments/:id/:style/:basename.:extension'
validates_attachment_presence :media
:path => ':rails_root/public/files/medias/:id/:style/:basename.:extension',
:url => '/files/medias/:id/:style/:basename.:extension'
validates_media_presence :media

def self.search(filter, page)
paginate :per_page => 20, :page => page,
:conditions => ['info like ?', "%#{filter}%"],
Expand All @@ -37,7 +37,7 @@ def self.search(filter, page)
# == Schema Information
# Schema version: 99999999999999
#
# Table name: attachments
# Table name: medias
#
# id :integer not null, primary key
# attachable_id :integer
Expand Down
4 changes: 2 additions & 2 deletions app/views/articles/_article.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
= f.input :public
= f.input :published
- f.inputs :name => "Arquivo", :id => "arquivos" do
= f.render_associated_form @article.attachments, :partial => "attachments/attachment"
= f.add_associated_link "+ Novo arquivo", :attachments, :partial => "attachments/attachment"
= f.render_associated_form @article.medias, :partial => "medias/nested"
= f.add_associated_link "+ Novo arquivo", :medias, :partial => "medias/nested"
=# f.input :published_at, :as => :string, :input_html => { :id => "calendar" }
.group.navform
= f.submit 'Salvar', :class => :button
Expand Down
20 changes: 0 additions & 20 deletions app/views/attachments/index.html.haml

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/attachments/show.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
</div>

<div class="left"> Sistema Gestao Integrada </div>
<div class="right"><code> <a href="/about"> SIG@ Alpha </a> / 2009</code> - Powered by Ruby, Rails & PostgreSQL <img src="/images/icons/ruby.png"></img></div>
<div class="right"><code> <a href="/about"> SIG@ Alpha </a></code><img src="/images/icons/ruby.png"></img></div>
<p> - Prefeitura Municial de Xlandia </p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
- semantic_form_for(@attachment, :html => {:multipart => true, :class => "form"}) do |f|
- semantic_form_for(@media, :html => {:multipart => true, :class => "form"}) do |f|
= f.input :media, :label => "Arquivo"

= f.input :info
.clear
.navform
= f.submit "Salvar &rarr;", :class => "button"
ou
= link_to 'Voltar', attachments_path
= link_to 'Voltar', medias_path
5 changes: 5 additions & 0 deletions app/views/medias/_nested.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.media
- f.inputs do
= f.input :kind, :as => :select, :collection => Media.get_kind_values
= f.input :value, :input_html => { :size => 15 }
= f.remove_link "remove"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.block
.content
%h2{:class => "title"} Editando Registro
.inner= render @attachment
.inner= render @media
20 changes: 20 additions & 0 deletions app/views/medias/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.block
.head
%h2.title Attachable
.content
%table{:class => "table"}
%tbody
%tr
%th Tipo
%th Info
-@medias.each do |media|
%tr
-if media.media_content_type =~ /^image/
%td= image_tag media.media.url(:thumb)
-else
%td== #{image_tag("/images/mime/#{choose_icon media.media_file_name}")} #{media.media_file_name}
%td= media.info

= will_paginate @medias
- sidebar do
= link_to 'Novo Registro', new_media_path, :class => 'icon iadd'
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.head
%h2 Novo registro
.content
.inner= render @attachment
.inner= render @media
13 changes: 13 additions & 0 deletions app/views/medias/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p>
<b>Attachable:</b>
<%=h @media.attachable %>
</p>

<p>
<b>Info:</b>
<%=h @media.info %>
</p>


<%= link_to 'Edit', edit_media_path(@media) %> |
<%= link_to 'Back', medias_path %>
Loading

0 comments on commit 9a741ff

Please sign in to comment.