Gerenciador de imagens em Rails para TinyMCE e FCKEditor

[EDIT]: Este post está seriamente desatualizado e não recomendo mais attachment_fu. Em todo caso, o TinyMCE está cada vez melhor e continua FREE.

Problema: Estou usando TinyMCE ou FCKEditor em minha aplicação Rails, quero um gerenciador de imagens pra ontem!

Problem: I´m using TinyMCE or FCKEditor in my Rails app and the File Mananger does not work ! I need this due yesterday!!

First Step: Use a plugin to insert this Rich-Text editors in Rails may prove to be a great time saver !
TinyMCE: http://github.com/kete/tiny_mce/tree/master
FCKEditor: http://rubyforge.org/projects/fckeditorp/

Optional: This article: http://wiki.rubyonrails.org/rails/pages/howtousetinymce raise some thoughts about security IMHO always a useful wast of brain cells..

Still if the plugin don´t do the image job try my fast solution -would be this: a iFrame below the text area!

iframe with files

iframe with files

-Because the plugin support drag-and-drop you can drag the thumbs or the full pictures and drop where you want.. great?!

Uploading:
demo-mng-upload1
Way simple..

Showing:
demo-msng-show

Ok.. basic Portuguese lesson:
lista = list
adicionar = add
Imagens de Notícias = News Pictures
Caminho: = path
Dimensões: = (like ~) width height
Tamanho: = size
Enviar = Send
Well you figure out the rest.. =)

How to do: You will need the following plugins:

  1. attachment_fu
  2. mislav-will_paginate

Now make a scaffold (just for laziness) with this params: mananger filename:string

Cause I don´t like migrations.. in your database create something like:

CREATE TABLE `mydatabase`.`manangers` (
`id` int(10) unsigned NOT NULL auto_increment,
`filename` varchar(80) default NULL,
`content_type` varchar(40) default NULL,
`size` int(10) unsigned default NULL,
`height` int(10) unsigned default NULL,
`width` int(10) unsigned default NULL,
PRIMARY KEY (`id`)
)

On CONTROLLER: manangers_controller.rb:
class ManangersController params[:page], :order =>"id DESC" # we want the new first
end

def show
@mananger = Mananger.find(params[:id])
end

def new
@mananger = Mananger.new
end

def create
@mananger = Mananger.new(params[:mananger])

respond_to do |format|
if @mananger.save
flash[:notice] = ‘Upload com sucesso.’
format.html { redirect_to(@mananger) }
format.xml { render :xml => @mananger, :status => :created, :location => @mananger }
else
flash[:notice] = ‘Falha no upload’
format.html { render :action => “new” }
format.xml { render :xml => @mananger.errors, :status => :unprocessable_entity }
end
end
end

def destroy
@mananger = Mananger.find(params[:id])
@mananger.destroy

respond_to do |format|
format.html { redirect_to(manangers_url) }
format.xml { head :ok }
end
end
end

On MODEL mananger.rb:
class Mananger " already exist !"

has_attachment :content_type => :image,
:path_prefix => ‘public/files’,
:storage => :file_system,
:size => 1..1048576, # 2MB
:partition => false
validates_as_attachment
end

On VIEWS we are gonna use 3:
index.html.erb:

Imagens de Notícias

<!–

–>
<!–

–>

80) %>
px x px
|

new.html.erb:

UPLOAD

{ :multipart => true }) do |f| %>

show.html.erb

Caminho:

Dimensões: px x px

Tamanho:

DONE !

Now.. you want to position this in a iframe over or under one Rich-Text WYSWIG insert something like this:

😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s